Difference between revisions of "Greasemonkey Manual:Installing Scripts"

From GreaseSpot Wiki
Jump to navigationJump to search
(Undo revision 5221 by 117.200.225.70 (Talk))
(jtv)
Line 1: Line 1:
{{Greasemonkey Manual TOC}}
var clipPage = document.getElementById('next_clip');


== About User Scripts ==
if(clipPage)
{
var getDownloaded = document.getElementById('downloaded');
var daURL = getDownloaded.getAttribute("href");
getDownloaded.parentNode.removeChild(getDownloaded);
var newDownload = document.createElement("a");
newDownload.innerHTML = '<a href=' + daURL + ' class=subplayer_button id=downloaded nofollow=true><img src=http://www-cdn.justin.tv/images/0px.gif><b>Download</b></a>';
var reportBefore = document.getElementById('reported');
reportBefore.parentNode.insertBefore(newDownload, reportBefore);
}


The purpose of [[Greasemonkey]] is to manage user scripts.
[[User script]]s allow the ''user'' to control the way they use the web, by customizing it with scripting.
The [https://addons.mozilla.org/firefox/addon/748 Greasemonkey extension] won't do any good without any scripts installed.


The first thing an eager user should do is find and install ''(or write!)'' a useful script.
// Lower the lights on clips pages.


:* 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].
if(lowLight && clipPage)
{
var noGigya = document.getElementById('gigya');
noGigya.parentNode.removeChild(noGigya);
GM_addStyle("#page_wrapper {color: #BBBBBB !important; background: #545454 !important; min-width: 970px; padding: 30px 0px; line-height: 22px !important;}");
GM_addStyle("body {background: #545454 !important;}");
GM_addStyle(".clip_title {color: #ABABAB !important;}");
GM_addStyle(".box {border: 1px solid #000000 !important; background: #AAAAAA !important; color: #DDDDDD !important;}");
GM_addStyle(".box a:link {color: #555555 !important; text-decoration: underline;}");
GM_addStyle(".comment_timestamp {color: #444444 !important;}");
GM_addStyle(".box a:visited {color: #555555 !important; text-decoration: underline;}");
GM_addStyle(".section_hdr_rlink a:link {color: #FFFFFF !important; text-decoration: underline;}");
GM_addStyle(".section_hdr_rlink a:visited {color: #888888 !important; text-decoration: underline;}");
GM_addStyle(".subplayer_button {color: #888888 !important; text-decoration: none !important; font-size: 100% !important;}");
GM_addStyle(".section a:link {color: #BBBBBB !important; text-decoration: none !important;}");
GM_addStyle(".section a:visited {color: #888888 !important; text-decoration: none !important;}");
GM_addStyle(".title a:link {color: #CCCCCC !important; text-decoration: none !important;}");
GM_addStyle(".title a:visited {color: #888888 !important; text-decoration: none !important;}");
GM_addStyle(".stat {color: #BBBBBB !important; text-decoration: none !important;}");
GM_addStyle(".stat {color: #888888 !important; text-decoration: none !important;}");
GM_addStyle(".panel {background: #444444 !important; border: 1px solid #000000 !important;}");
GM_addStyle(".comment_header {background: #888888 !important; border-: 1px solid #000000 !important; font-size: 115%; padding: 3px 5px; margin-bottom: 5px; line-height: 100%;}");
GM_addStyle(".comment_header a:link {color: #DDDDDD !important;}");
GM_addStyle(".comment_header a:visited {color: #DDDDDD !important;}");
GM_addStyle("input[type=text] {color: #CCCCCC !important; background: #777777 !important;}");
GM_addStyle("#new_comment {background: #AAAAAA !important; padding: 10px; margin-bottom: 10px; border: 1px solid #000000 !important;}");
GM_addStyle(".field {border: 1px solid #000000 !important; background: #777777 !important; color: #CCCCCC !important;}");
GM_addStyle("#subplayer_buttons #shared img {background:  url(http://www.pressstart.tv/pressstart/jtv/combined-clip.rd30a5c088d6fe9e29bb81a3a0ba7a387764c5dcc.gif) !important; background-position: -0px -48px !important; background-repeat: no-repeat;}");
GM_addStyle("#subplayer_buttons #shared:hover img {background:  url(http://www.pressstart.tv/pressstart/jtv/combined-clip.rd30a5c088d6fe9e29bb81a3a0ba7a387764c5dcc.gif) !important; background-position: -30px -48px !important; background-repeat: no-repeat;}");
GM_addStyle("#subplayer_buttons #reported img {background:  url(http://www.pressstart.tv/pressstart/jtv/combined-clip.rd30a5c088d6fe9e29bb81a3a0ba7a387764c5dcc.gif) !important; background-position: -30px -24px !important; background-repeat: no-repeat;}");
GM_addStyle("#subplayer_buttons #reported:hover img {background:  url(http://www.pressstart.tv/pressstart/jtv/combined-clip.rd30a5c088d6fe9e29bb81a3a0ba7a387764c5dcc.gif) !important; background-position: -60px -24px !important; background-repeat: no-repeat;}");
GM_addStyle("#subplayer_buttons #next_clip img {background:  url(http://www.pressstart.tv/pressstart/jtv/combined-clip.rd30a5c088d6fe9e29bb81a3a0ba7a387764c5dcc.gif) !important; background-position: -60px -0px !important; background-repeat: no-repeat;}");
GM_addStyle("#subplayer_buttons #next_clip:hover img {background:  url(http://www.pressstart.tv/pressstart/jtv/combined-clip.rd30a5c088d6fe9e29bb81a3a0ba7a387764c5dcc.gif) !important; background-position: -0px -24px !important; background-repeat: no-repeat;}");
GM_addStyle("#subplayer_buttons #downloaded img {background:  url(http://www.pressstart.tv/pressstart/jtv/combined-clip.rd30a5c088d6fe9e29bb81a3a0ba7a387764c5dcc.gif) !important; background-position: -0px -0px !important; background-repeat: no-repeat;}");
GM_addStyle("#subplayer_buttons #downloaded:hover img {background:  url(http://www.pressstart.tv/pressstart/jtv/combined-clip.rd30a5c088d6fe9e29bb81a3a0ba7a387764c5dcc.gif) !important; background-position: -30px -0px !important; background-repeat: no-repeat;}");
}


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 &rarr; Open File...] dialog to open it.
//
if(removeRelated)
{
var chipotlAway = document.getElementById('related');
chipotlAway.parentNode.removeChild(chipotlAway);
}


:* Any file that ends in '''<code>.user.js</code>''' is a valid Greasemonkey user script.
// Alters beta chat window size


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.
if(bigChat)
{
GM_addStyle(".wrapper {width: 78.581em !important;}");
GM_addStyle(".right_col {width: 32.8572em !important;}");
GM_addStyle("#chat_lines {height: 52.5em !important}");
var adAway = document.getElementById('ad_holder');
adAway.parentNode.removeChild(adAway);
}


== The Installation Dialog ==
if(noNext)
 
{
When navigating to a [[user script]], Greasemonkey will open its installation dialog instead of loading the script like a normal page.
nxGone = document.getElementById('floaty_text_nxtchan');
A thumbnail of this dialog is shown to the left.
nxGone.parentNode.removeChild(nxGone);
It displays the name and description of the script, if available, as well as the [[include and exclude rules]] that apply.
}
 
[[Image:Install-dialog.png|left|thumb|150px|GM Installation Dialog]]
 
;* The Install button
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].
 
;* The Cancel button
This button will cancel the installation of a script.
 
;* The View Script Source button
This button will allow viewing of the source code contained in the script.
At this point, [[Greasemonkey]] has already downloaded the [[user script]] in question to display the name and other details.
 
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]]. This is intentionally engineered to avoid a potential security problem. An evil server could deliver one innocent script for viewing, and on the second load an evil script for installing.
This approach ensures that the script is downloaded only once.  Upon examination of the visible script source, ''this copy'' is the script that will be installed.
 
Finally, in this window there is an information bar at the top similar to the Firefox extension installation security warning. This bar includes another Install button much like the the prior dialog. Clicking this button will also install the script. Using the [[Greasemonkey_Manual:Manage_Dialog|Manage Dialog]] is the next step.

Revision as of 18:43, 3 May 2010

var clipPage = document.getElementById('next_clip');

if(clipPage) { var getDownloaded = document.getElementById('downloaded'); var daURL = getDownloaded.getAttribute("href"); getDownloaded.parentNode.removeChild(getDownloaded); var newDownload = document.createElement("a"); newDownload.innerHTML = '<a href=' + daURL + ' class=subplayer_button id=downloaded nofollow=true><img src=http://www-cdn.justin.tv/images/0px.gif>Download</a>'; var reportBefore = document.getElementById('reported'); reportBefore.parentNode.insertBefore(newDownload, reportBefore); }


// Lower the lights on clips pages.

if(lowLight && clipPage) { var noGigya = document.getElementById('gigya'); noGigya.parentNode.removeChild(noGigya); GM_addStyle("#page_wrapper {color: #BBBBBB !important; background: #545454 !important; min-width: 970px; padding: 30px 0px; line-height: 22px !important;}"); GM_addStyle("body {background: #545454 !important;}"); GM_addStyle(".clip_title {color: #ABABAB !important;}"); GM_addStyle(".box {border: 1px solid #000000 !important; background: #AAAAAA !important; color: #DDDDDD !important;}"); GM_addStyle(".box a:link {color: #555555 !important; text-decoration: underline;}"); GM_addStyle(".comment_timestamp {color: #444444 !important;}"); GM_addStyle(".box a:visited {color: #555555 !important; text-decoration: underline;}"); GM_addStyle(".section_hdr_rlink a:link {color: #FFFFFF !important; text-decoration: underline;}"); GM_addStyle(".section_hdr_rlink a:visited {color: #888888 !important; text-decoration: underline;}"); GM_addStyle(".subplayer_button {color: #888888 !important; text-decoration: none !important; font-size: 100% !important;}"); GM_addStyle(".section a:link {color: #BBBBBB !important; text-decoration: none !important;}"); GM_addStyle(".section a:visited {color: #888888 !important; text-decoration: none !important;}"); GM_addStyle(".title a:link {color: #CCCCCC !important; text-decoration: none !important;}"); GM_addStyle(".title a:visited {color: #888888 !important; text-decoration: none !important;}"); GM_addStyle(".stat {color: #BBBBBB !important; text-decoration: none !important;}"); GM_addStyle(".stat {color: #888888 !important; text-decoration: none !important;}"); GM_addStyle(".panel {background: #444444 !important; border: 1px solid #000000 !important;}"); GM_addStyle(".comment_header {background: #888888 !important; border-: 1px solid #000000 !important; font-size: 115%; padding: 3px 5px; margin-bottom: 5px; line-height: 100%;}"); GM_addStyle(".comment_header a:link {color: #DDDDDD !important;}"); GM_addStyle(".comment_header a:visited {color: #DDDDDD !important;}"); GM_addStyle("input[type=text] {color: #CCCCCC !important; background: #777777 !important;}"); GM_addStyle("#new_comment {background: #AAAAAA !important; padding: 10px; margin-bottom: 10px; border: 1px solid #000000 !important;}"); GM_addStyle(".field {border: 1px solid #000000 !important; background: #777777 !important; color: #CCCCCC !important;}"); GM_addStyle("#subplayer_buttons #shared img {background: url(http://www.pressstart.tv/pressstart/jtv/combined-clip.rd30a5c088d6fe9e29bb81a3a0ba7a387764c5dcc.gif) !important; background-position: -0px -48px !important; background-repeat: no-repeat;}"); GM_addStyle("#subplayer_buttons #shared:hover img {background: url(http://www.pressstart.tv/pressstart/jtv/combined-clip.rd30a5c088d6fe9e29bb81a3a0ba7a387764c5dcc.gif) !important; background-position: -30px -48px !important; background-repeat: no-repeat;}"); GM_addStyle("#subplayer_buttons #reported img {background: url(http://www.pressstart.tv/pressstart/jtv/combined-clip.rd30a5c088d6fe9e29bb81a3a0ba7a387764c5dcc.gif) !important; background-position: -30px -24px !important; background-repeat: no-repeat;}"); GM_addStyle("#subplayer_buttons #reported:hover img {background: url(http://www.pressstart.tv/pressstart/jtv/combined-clip.rd30a5c088d6fe9e29bb81a3a0ba7a387764c5dcc.gif) !important; background-position: -60px -24px !important; background-repeat: no-repeat;}"); GM_addStyle("#subplayer_buttons #next_clip img {background: url(http://www.pressstart.tv/pressstart/jtv/combined-clip.rd30a5c088d6fe9e29bb81a3a0ba7a387764c5dcc.gif) !important; background-position: -60px -0px !important; background-repeat: no-repeat;}"); GM_addStyle("#subplayer_buttons #next_clip:hover img {background: url(http://www.pressstart.tv/pressstart/jtv/combined-clip.rd30a5c088d6fe9e29bb81a3a0ba7a387764c5dcc.gif) !important; background-position: -0px -24px !important; background-repeat: no-repeat;}"); GM_addStyle("#subplayer_buttons #downloaded img {background: url(http://www.pressstart.tv/pressstart/jtv/combined-clip.rd30a5c088d6fe9e29bb81a3a0ba7a387764c5dcc.gif) !important; background-position: -0px -0px !important; background-repeat: no-repeat;}"); GM_addStyle("#subplayer_buttons #downloaded:hover img {background: url(http://www.pressstart.tv/pressstart/jtv/combined-clip.rd30a5c088d6fe9e29bb81a3a0ba7a387764c5dcc.gif) !important; background-position: -30px -0px !important; background-repeat: no-repeat;}"); }

// if(removeRelated) { var chipotlAway = document.getElementById('related'); chipotlAway.parentNode.removeChild(chipotlAway); }

// Alters beta chat window size

if(bigChat) { GM_addStyle(".wrapper {width: 78.581em !important;}"); GM_addStyle(".right_col {width: 32.8572em !important;}"); GM_addStyle("#chat_lines {height: 52.5em !important}"); var adAway = document.getElementById('ad_holder'); adAway.parentNode.removeChild(adAway); }

if(noNext) { nxGone = document.getElementById('floaty_text_nxtchan'); nxGone.parentNode.removeChild(nxGone); }