簡體   English   中英

如何結合這兩個Greasemonkey腳本?

[英]How do I combine these 2 Greasemonkey scripts?

我需要結合這兩個通用腳本。 一個打開一個列表中的新頁面,另一個單擊“關注”按鈕。

腳本1: 如何自動順序打開頁面列表?

腳本2: 如何使用Greasemonkey單擊此按鈕?

我試圖將它們自己合並,但是未能創建一個可以完全重新加載頁面的工作腳本,即使它們被順序地放在列表中(如果您閱讀其他問題,您也會明白我的意思)。

這是我嘗試過的方法,但是由於無法正確地重新加載頁面並繼續執行其任務,因此無法正常工作:

// ==UserScript==
// @name    Follow People on INK361
// @description Follow People from our FB Page's list INK361
// @include     http://ink361.com*
// @require  http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require  https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant       GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a major design
    change introduced in GM 1.0.
    It restores the sandbox.
*/

var urlsToLoad  = [
'http://ink361.com/#/users/30742610/photos',
'http://ink361.com/#/users/193869245/photos',
'http://ink361.com/#/users/215062853/photos',
'http://ink361.com/#/users/218295575/photos'
];

/*--- Since many of these sites load large pictures, Chrome's and 
    Firefox's injection may fire a good deal before the image(s) 
    finish loading.
    So, insure script fires after load:
*/

//--- Catch new pages loaded by WELL BEHAVED ajax.
window.addEventListener ("hashchange", FireTimerA,  false);

function FiretimerA () {
    waitForKeyElements ("a.simplebutton:contains('follow')", FireTimer());
}


function FireTimer (jNode) {

    if ( ! /^\s*follow\s*$/i.test () ) {   
        return false;
    }

    var clickEvent  = document.createEvent ('MouseEvents');
    clickEvent.initEvent ('click', true, true);
    jNode[0].dispatchEvent (clickEvent);
    GotoNextURL();
}

function GotoNextURL () {
    var numUrls     = urlsToLoad.length;
    var urlIdx      = urlsToLoad.indexOf (location.href);
    urlIdx++;
    if (urlIdx >= numUrls)
        urlIdx = 0;

    location.href   = urlsToLoad[urlIdx];
}

合並這些腳本 應該很簡單:只需對元數據塊進行標准化,然后將一個腳本的javascript粘貼到另一個腳本之后。

確定合並腳本的真正目的后,我們得到:

// ==UserScript==
// @name        _Follow People on INK361
// @description Follow People from our FB Page's list INK361
// @include     http://ink361.com/#/users/*
// @exclude     http://ink361.com/#/users/223888036*
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require     https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant       GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a major design
    change introduced in GM 1.0.
    It restores the sandbox.
*/

var urlsToLoad  = [
    'http://ink361.com/#/users/14565576/photos'
    , 'http://ink361.com/#/users/218217815/photos'
    , 'http://ink361.com/#/users/202670894/photos'
    , 'http://ink361.com/#/users/201771644/photos'
    , 'http://ink361.com/#/users/217243779/photos'
    , 'http://ink361.com/#/users/218295748/photos'
    , 'http://ink361.com/#/users/218273533/photos'
    , 'http://ink361.com/#/users/30742610/photos'
    , 'http://ink361.com/#/users/193869245/photos'
    , 'http://ink361.com/#/users/215062853/photos'
];

/*--- Operation:
    1) If the button is "follow" then it clicks it.
    2) If the button is, or becomes "unfollow", then go to the next page.
    3) If there is no button or the button stops working, it stays on the current page.
*/

//--- Note that contains() is CASE-SENSITIVE.
waitForKeyElements (
    "#relationship a.simplebutton:contains('follow')",
    clickOnFollowButton
);

function clickOnFollowButton (jNode) {

    if ( /^\s*follow\s*$/i.test (jNode.text() ) ) {
        //--- Button is "follow"; click it.

        var clickEvent  = document.createEvent ('MouseEvents');
        clickEvent.initEvent ('click', true, true);
        jNode[0].dispatchEvent (clickEvent);
    }
    else if ( /^\s*unfollow\s*$/i.test (jNode.text() ) ) {
        //--- Unfollow button is already (or now) set.  Go to next page.
        jNode.text ("palate cleanser");
        GotoNextURL ();
    }

    return true;    //--- This node is reused, never mark it as found.
}


function GotoNextURL () {
    var numUrls     = urlsToLoad.length;
    var urlIdx      = urlsToLoad.indexOf (location.href);
    urlIdx++;

    //-- Don't loop the list of sites.
    if (urlIdx < numUrls) {
        location.assign (urlsToLoad[urlIdx]);
    }
}

但這假設單擊“跟隨”按鈕可使屏幕保持在同一頁面上。 可以? (是)

我無法登錄該站點,因此無法完全測試腳本。 如果它不起作用,請列出控制台(Firebug或Firefox)顯示的所有錯誤消息,並准確描述其行為。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM