User script: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
No edit summary
m Arantius moved page Category:User script to User script over a redirect without leaving a redirect: vandalism
 
(27 intermediate revisions by 14 users not shown)
Line 1: Line 1:
// ==UserScript==
User scripts are programs which make on-the-fly changes to specific web pages, typically to change their appearance or to add or modify functionality.
// @name          FFS Autobuy version 20091117
// @namespace      http://nguyducthuan.com
// @include        http://apps.facebook.com/friendsforsale/users/show/*
// @require        http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// @reference   http://userscripts.org/scripts/show/24984
// @implementation Nguy Duc Thuan
// ==/UserScript==
/*
This script is published under the MS-PL license which can be found on the following link:
http://www.opensource.org/licenses/ms-pl.html
In short: The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions.
*/
var _delay = 5000;
var MAXVALUE = 1000000000;
var FFS =
{
    performClick: function(node)
    {
        var evt = document.createEvent("MouseEvents");
        evt.initEvent("click", true, false);
        node.dispatchEvent(evt);
    },
    work: function()
    {
        var buyFor = FFS.findBuyFor();
        if (buyFor == null)
        {
            setTimeout(FFS.doReload, _delay);
            return;
        }
        if (!FFS.checkValue())
        {
            alert('Pre-specified max value reaches');
            return;
        }
        FFS.performClick(buyFor);
        setTimeout(FFS.confirmPurchase, _delay);
    },
    checkValue: function()
    {
        var valueElement = $(".action_container > .actions > .buy > .sliding_window_left > .sliding_window_right > .sliding_window_bottom > .sliding_window_corner > a > span > strong")[0];
        var value = valueElement.firstChild.textContent.replace(/[\$,\.]/g, '');
        value = parseInt(value, 10);
        if (value >= MAXVALUE)
            return false;
        return true;
    },
    confirmPurchase: function()
    {
        var func = $(".sliding_window_left > .sliding_window_right > .sliding_window_bottom > .sliding_window_corner > a");
        if (func.length == 0)
            return;
        FFS.performClick(func[1]);  // there are two such <a> tags. The second one is what we need
        setTimeout(FFS.doReload, _delay);
    },
    doReload: function()
    {
        document.location.reload();
    },
    findBuyFor: function()
    {
        var x = $(".action_container > .actions > .buy > .sliding_window_left > .sliding_window_right > .sliding_window_bottom > .sliding_window_corner > a"); //.buy
        if (x.length == 0)
            return null;
        return x[0];
    }
}


setTimeout(FFS.work, _delay);
User scripts for [[Greasemonkey]] and Greasemonkey-compatible alternatives are written in [http://developer.mozilla.org/en/docs/JavaScript JavaScript].
If you would like to write user scripts yourself, see [[Greasemonkey Manual:Editing]].
 
== See Also ==
* [[wikipedia:Augmented browsing|Augmented browsing at Wikipedia]]

Latest revision as of 23:58, 17 April 2024

User scripts are programs which make on-the-fly changes to specific web pages, typically to change their appearance or to add or modify functionality.

User scripts for Greasemonkey and Greasemonkey-compatible alternatives are written in JavaScript. If you would like to write user scripts yourself, see Greasemonkey Manual:Editing.

See Also