2013-03-22 34 views
1

我創建了這個Greasemonkey用於批量關注/取消關注Twitter用戶。該腳本工作得很好。但是,當我第一次訪問包含列表中的某個頁面時,它不會總是(幾乎不會)加載。Greasemonkey腳本只能用CTRL + F5加載?

舉例來說,如果我去twitter.com/followers,該腳本將不會加載,除非我用CTRLF5(從服務器刷新頁面內容)。

我不確定這是Greasemonkey腳本應該運行的方式,還是我需要更改代碼中的某些內容?

我的GM腳本:

// ==UserScript== 
// @name   Brainstack.net "YOU Follow (Beta)" 
// @namespace  net.brainstack.gm 
// @description  Script for automating the following of users from the Twitter Followers page 
// @require   http://gm.brainstack.net/tasa/tasa.js 
// @resource  tasa_CSS http://gm.brainstack.net/tasa/tasa.css 
// @downloadURL  http://gm.brainstack.net/tasa/Brainstack.net_tasa.user.js 
// @updateURL  http://gm.brainstack.net/tasa/Brainstack.net_tasa.meta.js 
// @include   https://twitter.com/followers* 
// @include   https://www.twitter.com/followers* 
// @include   https://twitter.com/*/followers* 
// @include   https://www.twitter.com/*/followers* 
// @include   https://twitter.com/*/following* 
// @include   https://www.twitter.com/*/following* 
// @include   https://twitter.com/following* 
// @include   https://www.twitter.com/following* 
// @include   https://twitter.com/search/users?* 
// @run-at   document-end 
// @grant   GM_getResourceText 
// @grant   GM_addStyle 
// @version   1.14 
// ==/UserScript== 

//add CSS to head 
var CSS = GM_getResourceText("tasa_CSS"); 
GM_addStyle(CSS); 

//hook to the page load 
bsnet_app_page_load(); 

你可以download and/or install the script at gm.brainstack.net

謝謝!

+0

+1通過鏈接包含完整的代碼。但是這個Q值接近「本地化」和/或代碼審查。 (大部分代碼都在'tasa.js'中,這對於一個SO問題來說有點太過分了。試着將代碼縮減爲[SSCCE](http://sscce.org/) – 2013-03-23 00:12:17

回答

1

此問題與I have to refresh the page for my Greasemonkey script to run?所涵蓋的問題類型相同。閱讀,理解並使用該答案的技巧,在「新」頁面上「觸發」您的腳本。

此外,腳本代碼在tasa.js有喜歡的東西:

var localStorageString = localStorage['bsnet_app_follower']; 
if (localStorageString.length > 0){ 

其崩潰的腳本,尤其是在早期運行。

這樣的代碼應該是

var localStorageString = localStorage['bsnet_app_follower']; 
if (localStorageString && localStorageString.length > 0){ 


可能有其他問題(沒有看到任何一眼,沒有調試腳本或者)但這不是代碼審查的地方。

+0

Thanks @brock。我非常感謝您的反饋,我將通過其他文章並將這些技術應用到我的腳本中。很難不讓同行審閱我的代碼;-) – 2013-03-23 13:30:32

+0

不客氣,祝您好運。有[代碼評論網站](http://codereview.stackexchange.com/)。 – 2013-03-23 13:38:32

相關問題