1

I created this Greasemonkey for batch following/unfollowing Twitter users. The script works just fine. However, it won't always (almost never) load the first time I go to one of the pages on the include list.

For instance, if I go to twitter.com/followers, the script won't load unless I use CTRLF5 (which refreshes the page contents from the server).

I am not sure whether this is how Greasemonkey scripts are supposed to run, or there is something in my code that I need to change?

My GM script:

// ==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();

You can download and/or install the script at gm.brainstack.net.

Thanks!

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
Alex Pereira
  • 160
  • 1
  • 1
  • 9
  • +1 for including full code via links. But this Q is close to "Too localized" and/or a code review. (The bulk of the code is in `tasa.js` and that's a bit much for an SO question. Try to pare question code down to [an SSCCE](http://sscce.org/). – Brock Adams Mar 23 '13 at 00:12

1 Answers1

1

This problem is the same type of issue covered by I have to refresh the page for my Greasemonkey script to run?.   Read, understand, and use the techniques of that answer to "fire" your script on "new" pages.

Additionally, the script code in tasa.js has things like:

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

which crash the script, especially on early runs.

That kind of code should be:

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


There may be other issues (didn't see any at a glance; didn't debug the script either), but this is not the place for code review.

Community
  • 1
  • 1
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
  • Thanks @brock. I appreciate your feedback. I will go through the other post and apply the techniques to my script. It's hard not having a peer to review my code ;-) – Alex Pereira Mar 23 '13 at 13:30
  • You're welcome and good luck. There is [a site for code reviews](http://codereview.stackexchange.com/). – Brock Adams Mar 23 '13 at 13:38