sort greasemonkey user-scripts alphabetically

Talk about add-ons and extension development.
Post Reply
User avatar
GarethB
Posts: 118
Joined: May 7th, 2006, 9:11 am
Contact:

sort greasemonkey user-scripts alphabetically

Post by GarethB »

I've been looking through Google and www.userscripts.org for a script that lets you sort your user-scripts alphabetically, but I can't find any script that lets you do that [under the 'Manage User Scripts' page].

could anyone help me with this please?

thanks in advance :)
Zoolcar9
Posts: 2225
Joined: November 9th, 2004, 6:45 pm
Location: Jakarta, Indonesia (UTC+7)
Contact:

Post by Zoolcar9 »


That's impossible.

My Firefox information | Add-ons | GitHub

"With great power, comes great desire to show it off."
User avatar
GarethB
Posts: 118
Joined: May 7th, 2006, 9:11 am
Contact:

Post by GarethB »

sorry, but how the heck is it impossible? O_o
User avatar
Grist
Posts: 836
Joined: January 27th, 2006, 9:20 pm

Post by Grist »

User scripts can only change web content. The extension itself would have to be modified. I did find a hack in the GM archives:
http://mozdev.org/pipermail/greasemonke ... 08766.html

It hasn't been thoroughly tested so I can't guarantee it won't break something. I tried it and it seems to work but I can't predict what might go wrong.
Zoolcar9
Posts: 2225
Joined: November 9th, 2004, 6:45 pm
Location: Jakarta, Indonesia (UTC+7)
Contact:

Post by Zoolcar9 »


Ah, great! Then we can use userChrome.js script with WindowHook snippet.

Code: Select all

/* insert WindowHook snippet here */

WindowHook.register("chrome://greasemonkey/content/manage.xul",
  function(aWindow) {
    function populateChooser_sorted() {
      var sortedScripts = aWindow.config.scripts.slice(0,aWindow.config.scripts.length);
      sortedScripts.sort(
        function(a,b) {
          a=a.name.toLowerCase();
          b=b.name.toLowerCase();
          if (a < b) return -1;
          if (a > b) return 1;
          return 0;
        }
      )
      for (var i = 0, script = null; (script = sortedScripts[i]); i++) {
        var listitem = aWindow.document.createElement("listitem");
        listitem.setAttribute("label", script.name);
        listitem.setAttribute("crop", "end");
        listitem.script = script;
        if (!script.enabled) {
          listitem.style.color = 'gray';
        }
        aWindow.listbox.appendChild(listitem);
      }
    }
  aWindow.populateChooser = populateChooser_sorted;
  }
);

Thanks, Grist
Last edited by Zoolcar9 on November 20th, 2006, 3:25 pm, edited 1 time in total.
My Firefox information | Add-ons | GitHub

"With great power, comes great desire to show it off."
User avatar
GarethB
Posts: 118
Joined: May 7th, 2006, 9:11 am
Contact:

Post by GarethB »

yeah, thanks alot Grist! Just one last question ^^;

do I copy & paste BOTH of those scripts into my userChrome.js, or just one of them? [if 1, which one is it?]
Zoolcar9
Posts: 2225
Joined: November 9th, 2004, 6:45 pm
Location: Jakarta, Indonesia (UTC+7)
Contact:

Post by Zoolcar9 »


If you already have WindowHook snippet in your userChrome.js, you just have to copy the code above. If not, copy both (<a class="postlink" href="data:text/javascript,%2F*%20%3A%3A%3A%3A%3A%3A%3A%3A%20WindowHook%20%3A%3A%3A%3A%3A%3A%3A%3A%3A%3A%3A%3A%3A%3A%3A%20*%2F%0A%0Avar%20WindowHook%20%3D%20%7B%0A%09observe%3A%20function(aSubject%2C%20aTopic%2C%20aData)%0A%09%7B%0A%09%09if%20(!aSubject._WindowHook)%0A%09%09%7B%0A%09%09%09aSubject._WindowHook%20%3D%20this%3B%0A%09%09%09aSubject.addEventListener(%22load%22%2C%20this.onLoad_window%2C%20false)%3B%0A%09%09%7D%0A%09%7D%2C%0A%0A%09onLoad_window%3A%20function()%0A%09%7B%0A%09%09this.removeEventListener(%22load%22%2C%20this._WindowHook.onLoad_window%2C%20false)%3B%0A%09%09var%20funcs%20%3D%20this._WindowHook.mFuncs%5Bthis.document.location.href%5D%20%7C%7C%20null%3B%0A%09%09if%20(funcs)%0A%09%09%7B%0A%09%09%09funcs.forEach(function(aFunc)%20%7B%20aFunc(this)%3B%20%7D%2C%20this)%3B%0A%09%09%7D%0A%09%09delete%20this._WindowHook%3B%0A%09%7D%2C%0A%0A%09register%3A%20function(aURL%2C%20aFunc)%0A%09%7B%0A%09%09if%20(!this.mFuncs)%0A%09%09%7B%0A%09%09%09this.mFuncs%20%3D%20%7B%7D%3B%0A%09%09%09Components.classes%5B%22%40mozilla.org%2Fobserver-service%3B1%22%5D.getService(Components.interfaces.nsIObserverService).addObserver(this%2C%20%22domwindowopened%22%2C%20false)%3B%0A%09%09%7D%0A%09%09if%20(!this.mFuncs%5BaURL%5D)%0A%09%09%7B%0A%09%09%09this.mFuncs%5BaURL%5D%20%3D%20%5B%5D%3B%0A%09%09%7D%0A%09%09this.mFuncs%5BaURL%5D.push(aFunc)%3B%0A%09%7D%0A%7D%3B%0A">WindowHook</a> first, then the above code).

My Firefox information | Add-ons | GitHub

"With great power, comes great desire to show it off."
Post Reply