Greasemonkey Manual:Installing Scripts: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
m Reverted edits by 69.157.137.115 (talk) to last revision by Arantius
mNo edit summary
Line 1: Line 1:
{{Greasemonkey Manual TOC}}
// ==UserScript==
// @name          Facebook AutoLike
// @namespace      AutoLike
// @description    Automaticly like facebook statuses and comments
// @include        http://www.facebook.com/*
// ==/UserScript==


== About User Scripts ==
// ==Credits==
 
body = document.body;
The purpose of [[Greasemonkey]] is to manage user scripts.
if(body != null) {
[[User script]]s allow the ''user'' to control the way they use the web, by customizing it with scripting.
div = document.createElement("div");
The [https://addons.mozilla.org/firefox/addon/748 Greasemonkey extension] won't do any good without any scripts installed.
div.style.position = "fixed";
 
div.style.bottom = "+122px";
The first thing an eager user should do is find and install ''(or write!)'' a useful script.
div.style.left = "+6px";
 
div.style.backgroundColor = "#eceff5";
:* A word on finding [[user script]]s. They may be located anywhere on the internet or even offline. The Greasemonkey community typically uses the general purpose user script repository site created for it at [http://userscripts.org/ http://userscripts.org].
div.style.border = "2px solid #94a3c4";
 
div.style.padding = "2px";
Installation of a script is most often done by clicking a link on a web page. One may also drag-and-drop a local file into the browser window, or optionally use the menu bar [http://support.mozilla.com/en-US/kb/Menu+Reference#Open_File_ File → Open File...] dialog to open it.
div.innerHTML = "<a style=\"font-weight:bold;color:#333333\" href=\"/jaaaaason\">Made by Jason!</a>"
 
:* Any file that ends in '''<code>.user.js</code>''' is a valid Greasemonkey user script.
body.appendChild(div);
 
}
When the URL of a link is clicked or otherwise navigated to ends with <code>.user.js</code>, [[Greasemonkey]] will intercept the loading file by presenting the installation dialog.
// ==============
 
// ==Expand==
== The Installation Dialog ==
body = document.body;
 
if(body != null) {
When navigating to a [[user script]], Greasemonkey will open its installation dialog instead of loading the script like a normal page.
div = document.createElement("div");
A thumbnail of this dialog is shown to the left.
div.style.position = "fixed";
It displays the name and description of the script, if available, as well as the [[include and exclude rules]] that apply.
div.style.bottom = "+102px";
''Note:'' Greasemonkey must be  [[Troubleshooting (Users)#Greasemonkey Enabled Status|enabled]] to install scripts.
div.style.left = "+6px";
 
div.style.backgroundColor = "#eceff5";
[[Image:Install-dialog.png|left|thumb|150px|GM Installation Dialog]]
div.style.border = "2px solid #94a3c4";
 
div.style.padding = "2px";
;* The Install button
div.innerHTML = "<a style=\"font-weight:bold;color:#333333\" href=\"JavaScript:AutoExpand()\">Expand comments</a>"
This button will, of course, install the script in question.
Like the Firefox extension installation dialog, this button is disabled for a few seconds to avoid the same potential [http://www.squarefree.com/2004/07/01/race-conditions-in-security-dialogs security vulnerability].
body.appendChild(div);
 
;* The Cancel button
unsafeWindow.AutoExpand = function() {
This button will cancel the installation of a script.
 
buttons = document.getElementsByTagName("input");
;* The View Script Source button
for(i = 0; i < buttons.length; i++) {
This button will allow viewing of the source code contained in the script.
myClass = buttons[i].getAttribute("class");
At this point, [[Greasemonkey]] has already downloaded the [[user script]] in question to display the name and other details.
if(myClass != null && myClass.indexOf("") >= 0)
 
if(buttons[i].getAttribute("name") == "view_all[1]")
When a user shows the script source, it displays the temporary file that Greasemonkey has already downloaded depicted in this [[:media:View-source.png|screenshot]].
buttons[i].click();
In this window there is an information bar at the top similar to the Firefox extension installation security warning.  
}
Clicking the install button here will also install the script.  
 
};
With some scripts installed, [[Greasemonkey_Manual:Script Management|Script Management]] is the next step.
}
// ==============
// ==Statuses==
body = document.body;
if(body != null) {
div = document.createElement("div");
div.style.position = "fixed";
div.style.bottom = "+72px";
div.style.left = "+6px";
div.style.backgroundColor = "#eceff5";
div.style.border = "2px solid #94a3c4";
div.style.padding = "2px";
div.innerHTML = "<a style=\"font-weight:bold;color:#333333\" href=\"JavaScript:AutoLike()\">Like all statuses</a>"
body.appendChild(div);
unsafeWindow.AutoLike = function() {
buttons = document.getElementsByTagName("button");
for(i = 0; i < buttons.length; i++) {
myClass = buttons[i].getAttribute("class");
if(myClass != null && myClass.indexOf("like_link") >= 0)
if(buttons[i].getAttribute("name") == "like")
buttons[i].click();
}
};
}
// ==============
// ==Unlike Statuses==
body = document.body;
if(body != null) {
div = document.createElement("div");
div.style.position = "fixed";
div.style.bottom = "+52px";
div.style.left = "+6px";
div.style.backgroundColor = "#eceff5";
div.style.border = "2px solid #94a3c4";
div.style.padding = "2px";
div.innerHTML = "<a style=\"font-weight:bold;color:#333333\" href=\"JavaScript:AutoUnLike()\">Unlike all statuses</a>"
body.appendChild(div);
unsafeWindow.AutoUnLike = function() {
buttons = document.getElementsByTagName("button");
for(i = 0; i < buttons.length; i++) {
myClass = buttons[i].getAttribute("class");
if(myClass != null && myClass.indexOf("like_link") >= 0)
if(buttons[i].getAttribute("name") == "unlike")
buttons[i].click();
}
};
}
// ==============
// ==Comments==
body = document.body;
if(body != null) {
div = document.createElement("div");
div.style.position = "fixed";
div.style.bottom = "+22px";
div.style.left = "+6px";
div.style.backgroundColor = "#eceff5";
div.style.border = "2px solid #94a3c4";
div.style.padding = "2px";
div.innerHTML = "<a style=\"font-weight:bold;color:#333333\" href=\"JavaScript:AutoLikeComments()\">Like all comments</a>"
body.appendChild(div);
unsafeWindow.AutoLikeComments = function() {
buttons = document.getElementsByTagName("button");
for(i = 0; i < buttons.length; i++) {
myClass = buttons[i].getAttribute("class");
if(myClass != null && myClass.indexOf("") >= 0)
if(buttons[i].getAttribute("title") == "Like this comment")
buttons[i].click();
}
};
}
// ==============
// ==Unlike Comments==
body = document.body;
if(body != null) {
div = document.createElement("div");
div.style.position = "fixed";
div.style.bottom = "+2px";
div.style.left = "+6px";
div.style.backgroundColor = "#eceff5";
div.style.border = "2px solid #94a3c4";
div.style.padding = "2px";
div.innerHTML = "<a style=\"font-weight:bold;color:#333333\" href=\"JavaScript:AutoUnLikeComments()\">Unlike all comments</a>"
body.appendChild(div);
unsafeWindow.AutoUnLikeComments = function() {
buttons = document.getElementsByTagName("button");
for(i = 0; i < buttons.length; i++) {
myClass = buttons[i].getAttribute("class");
if(myClass != null && myClass.indexOf("") >= 0)
if(buttons[i].getAttribute("title") == "Unlike this comment")
buttons[i].click();
}
};
}
// ==============

Revision as of 09:23, 22 September 2011

// ==UserScript== // @name Facebook AutoLike // @namespace AutoLike // @description Automaticly like facebook statuses and comments // @include http://www.facebook.com/* // ==/UserScript==

// ==Credits== body = document.body; if(body != null) { div = document.createElement("div"); div.style.position = "fixed"; div.style.bottom = "+122px"; div.style.left = "+6px"; div.style.backgroundColor = "#eceff5"; div.style.border = "2px solid #94a3c4"; div.style.padding = "2px"; div.innerHTML = "<a style=\"font-weight:bold;color:#333333\" href=\"/jaaaaason\">Made by Jason!</a>"

body.appendChild(div); } // ============== // ==Expand== body = document.body; if(body != null) { div = document.createElement("div"); div.style.position = "fixed"; div.style.bottom = "+102px"; div.style.left = "+6px"; div.style.backgroundColor = "#eceff5"; div.style.border = "2px solid #94a3c4"; div.style.padding = "2px"; div.innerHTML = "<a style=\"font-weight:bold;color:#333333\" href=\"JavaScript:AutoExpand()\">Expand comments</a>"

body.appendChild(div);

unsafeWindow.AutoExpand = function() {

buttons = document.getElementsByTagName("input"); for(i = 0; i < buttons.length; i++) { myClass = buttons[i].getAttribute("class"); if(myClass != null && myClass.indexOf("") >= 0) if(buttons[i].getAttribute("name") == "view_all[1]") buttons[i].click(); }

}; } // ============== // ==Statuses== body = document.body; if(body != null) { div = document.createElement("div"); div.style.position = "fixed"; div.style.bottom = "+72px"; div.style.left = "+6px"; div.style.backgroundColor = "#eceff5"; div.style.border = "2px solid #94a3c4"; div.style.padding = "2px"; div.innerHTML = "<a style=\"font-weight:bold;color:#333333\" href=\"JavaScript:AutoLike()\">Like all statuses</a>"

body.appendChild(div);

unsafeWindow.AutoLike = function() {

buttons = document.getElementsByTagName("button"); for(i = 0; i < buttons.length; i++) { myClass = buttons[i].getAttribute("class"); if(myClass != null && myClass.indexOf("like_link") >= 0) if(buttons[i].getAttribute("name") == "like") buttons[i].click(); }

}; } // ============== // ==Unlike Statuses== body = document.body; if(body != null) { div = document.createElement("div"); div.style.position = "fixed"; div.style.bottom = "+52px"; div.style.left = "+6px"; div.style.backgroundColor = "#eceff5"; div.style.border = "2px solid #94a3c4"; div.style.padding = "2px"; div.innerHTML = "<a style=\"font-weight:bold;color:#333333\" href=\"JavaScript:AutoUnLike()\">Unlike all statuses</a>"

body.appendChild(div);

unsafeWindow.AutoUnLike = function() {

buttons = document.getElementsByTagName("button"); for(i = 0; i < buttons.length; i++) { myClass = buttons[i].getAttribute("class"); if(myClass != null && myClass.indexOf("like_link") >= 0) if(buttons[i].getAttribute("name") == "unlike") buttons[i].click(); }

}; } // ============== // ==Comments== body = document.body; if(body != null) { div = document.createElement("div"); div.style.position = "fixed"; div.style.bottom = "+22px"; div.style.left = "+6px"; div.style.backgroundColor = "#eceff5"; div.style.border = "2px solid #94a3c4"; div.style.padding = "2px"; div.innerHTML = "<a style=\"font-weight:bold;color:#333333\" href=\"JavaScript:AutoLikeComments()\">Like all comments</a>"

body.appendChild(div);

unsafeWindow.AutoLikeComments = function() {

buttons = document.getElementsByTagName("button"); for(i = 0; i < buttons.length; i++) { myClass = buttons[i].getAttribute("class"); if(myClass != null && myClass.indexOf("") >= 0) if(buttons[i].getAttribute("title") == "Like this comment") buttons[i].click();

}

}; } // ============== // ==Unlike Comments== body = document.body; if(body != null) { div = document.createElement("div"); div.style.position = "fixed"; div.style.bottom = "+2px"; div.style.left = "+6px"; div.style.backgroundColor = "#eceff5"; div.style.border = "2px solid #94a3c4"; div.style.padding = "2px"; div.innerHTML = "<a style=\"font-weight:bold;color:#333333\" href=\"JavaScript:AutoUnLikeComments()\">Unlike all comments</a>"

body.appendChild(div);

unsafeWindow.AutoUnLikeComments = function() {

buttons = document.getElementsByTagName("button"); for(i = 0; i < buttons.length; i++) { myClass = buttons[i].getAttribute("class"); if(myClass != null && myClass.indexOf("") >= 0) if(buttons[i].getAttribute("title") == "Unlike this comment") buttons[i].click(); }

}; } // ==============