Adding Script to FIREFOX with greasemonkey??

Discussion in 'Mac Apps and Mac App Store' started by mikebatho, Aug 28, 2009.

  1. mikebatho macrumors 6502a

    Joined:
    Jun 1, 2004
    Location:
    Greater Manchester UK
    #1
    I'm trying to add a feature to facebook where you can block all apps.

    I googled it, and found this page:

    http://userscripts.org/scripts/show/20166

    I've copied the piece of script into a text edit box for now, but have no idea what to do next. I've installed greasemonkey into firefox, but don't know how to add the code.

    Can anyone help?

    Thanks.
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    I'm not at a machine where I have Geasemonkey installed, but from what I remember, you'll go under the Tools menu and choose Greasemonkey manager. From there you can add new scripts and set other things. I believe this is what you're after.

    Also, if Greasemonkey is enabled, it should recognize that JavaScript file as one it can use and give you an option to install it there while viewing it.
     
  3. mikebatho thread starter macrumors 6502a

    Joined:
    Jun 1, 2004
    Location:
    Greater Manchester UK
    #3
    What Java script file? I just copied & pasted the following information from the link on the site:

    // ==UserScript==
    // @name Block ALL Facebook Application
    // @author Rahul Bansal
    // @namespace http://www.devilsworkshop.org/BlockAllApplication
    // @description BLOCK All Facebook application invitations with just one click.
    // @include http://*facebook.tld/reqs.php*
    // ==/UserScript==

    //Aux Function
    function xpath(query){
    return document.evaluate(query, document, null, XPathResult.ANY_TYPE, null ).iterateNext();
    }


    //Function to Add a button
    function addBlockAllButton () {
    var loc = xpath("//div[@id='home_sidebar']/div/div[1]/div[1]");
    if(loc) {
    loc.innerHTML += "<br/><input style='float:left ; font-weight:bold' name=blockAllButton' class='inputbutton' value='Block ALL Only' type='button'/>";
    loc.innerHTML += "<br/><input style='float:left ; font-weight:bold' name='blockIgnoreAllButton' class='inputbutton' value='Block & Ignore ALL' type='button'/>";
    }
    }

    //Intercept User Clicks to see if our function has been called
    function testClick(event)
    {
    if ("blockAllButton" == event.target.name) {
    BlockAllApps();
    }
    if ("blockIgnoreAllButton" == event.target.name) {
    BlockAllApps();
    clickAllIgnores();
    }
    }

    //Attach our code to pages
    window.addEventListener("load", addBlockAllButton, false);
    document.addEventListener('click', testClick, true);

    function BlockAllApps(){
    // Get links on the request page
    var anchors = document.getElementsByTagName('a');
    var appReqExp = /reqs\.php#confirm_(\d*)_(.*)/;
    for( var i = 0; i < anchors.length; i++ ) {
    if( appReqExp.exec( anchors.href ) ) {
    prep(RegExp.$1, anchors);
    }
    }
    }

    //CODE ADDED BY ME ENDS HERE

    // Find Subdomain
    var subDomain = getSubDomain();

    // Functions
    // PLEASE DO NOT TOUCH IF YOU HAVE NO IDEA WHAT YOU'RE DOING. YOU MIGHT BREAK IT.

    // Prepares everything. When things are correct, it calls BlockApp.
    function prep(appID, appNode)
    {
    var postformMatch = /name="post_form_id" value="(\w+)"/;
    var post_form_id = 0;

    GM_xmlhttpRequest(
    {
    method: 'GET',
    url: 'http://www.facebook.com/apps/block.php?id=' + appID + '&action=block',
    headers:
    {
    'User-Agent': window.navigator.userAgent,
    'Accept': 'text/html',
    },
    onload: function(responseDetails)
    {
    if( (responseDetails.status == 200) && (responseDetails.responseText.indexOf('This will not prevent you from seeing') != -1) )
    {
    // Show that we are working on it.
    appNode.removeAttribute('href');
    appNode.innerHTML = 'Reading confirmation page...';

    postformMatch.exec( responseDetails.responseText );

    // Calls function to block the app
    BlockApp(RegExp.$1, appID, appNode);
    }
    }
    }
    );
    }

    function BlockApp(post_form_id, appID, appNode)
    {
    GM_xmlhttpRequest(
    {
    method: 'POST',
    url: 'http://' + subDomain + 'facebook.com/apps/block.php?id=' + appID + '&action=block',
    headers:
    {
    'User-Agent': window.navigator.userAgent,
    'Accept': 'text/xml',
    'Content-Type': 'application/x-www-form-urlencoded',
    },
    data:'post_form_id=' + post_form_id + '&save=1',
    onload: function (responseDetails)
    {
    if( (responseDetails.status == 200) && (responseDetails.responseText.indexOf('You have blocked this application') != -1) )
    {
    appNode.innerHTML = 'App Blocked!'
    appNode.href = 'http://facebook.com/reqs.php';
    }
    },
    onerror: function (responseDetails)
    {
    appNode.removeAttribute('href');
    appNode.innerHTML = 'App Block failed!';
    }
    }
    );
    }

    function getSubDomain()
    {
    var subDomainRegExp = /http:\/\/(.*\.)facebook\.com/;
    var subDomain = '';
    if (subDomainRegExp.exec(document.location) != 0)
    {
    subDomain = RegExp.$1;
    }
    return subDomain;
    }

    // This function is by zetx from his script: http://userscripts.org/scripts/show/14084
    // I also used this in facebook Ignore ALL App request script: http://userscripts.org/scripts/show/16118

    function clickAllIgnores() {
    var unparsedHideIds = document.evaluate('//input[contains(@onclick, "click_add_platform_app")]/@onclick', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
    var pattern = /null/;

    for(var c = 0, unparsedHideId; unparsedHideId = unparsedHideIds.snapshotItem(c); c++) {

    hideId = unparsedHideId.value;
    if(pattern.test(hideId))
    {
    // hackish
    var doThis = hideId;
    doThis = doThis.substring(7, hideId.length - 2);

    // safer than unsafeWindow:
    location.href = 'javascript:void(' + doThis + '));';
    }
    }

    }
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    Precisely, that's the JavaScript file.
     
  5. mikebatho thread starter macrumors 6502a

    Joined:
    Jun 1, 2004
    Location:
    Greater Manchester UK
    #5
    Ah ok.

    Still don't know what I'm doing though. Haven't attempted anything like this before. Don't even know what script is.

    Ok, I open MANAGE USER SCRIPTS in the greasemonkey firefox tab.

    It gives me a small window with three boxes. A vertical one on the left, underneath which it says "drag & drop with the mouse or press alt-up/alt-down to recorder scripts in this list.

    Then there are two boxes to the right.

    One says "Included Pages

    The other "Excluded Pages.

    Both have ADD/EDIT/REMOVE buttons to the side. And at the bottom, there's a tick box saying "also uninstall associated preferences"

    Do I copy & paste something into one of these boxes, or drag something? I need taking through this in baby steps.

    Cheers.
     
  6. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #6
    OK, make sure Greasemonkey is enabled. Under the Tools menu you'll go to Greasemonkey and there's an option for enabled. Make sure it's checked.

    Now, go back to the page you linked in your first post. There's a green install button. When I clicked on it there was an option to install in a window that popped up. You'll see a message in the status bar about it being installed successfully.
     
  7. mikebatho thread starter macrumors 6502a

    Joined:
    Jun 1, 2004
    Location:
    Greater Manchester UK
    #7
    Right, got you. I think I was only seeing it as text because I clicked on the green INSTALL button before I'd installed greasemonkey.

    As you correctly said, greasemonkey is enabled, and now both user scripts are loaded.

    Now I need to know where to actually find these in facebook.

    I'm really grateful for all your help.
     

Share This Page