• GreaseMonkey script for garrysmod.org - faster downloads
    10 replies, posted
This is a GreaseMonkey script to speed up downloads on garrysmod.org by skipping the Codeen mirror. I've taken the old script by aVoN and rewrote it to suit the new uploads being served by the Amazon S3, since most recent ones would fail. [cpp] // ==UserScript== // @name GarrysMod.org speedup // @namespace DfKimera/aVoN // @description Speeds up the downloads on garrysmod.org by bypassing the mirrorsite coblitz.codeen.org to download directly the mirrors. 0.6 now lists available mirrors. // @version 0.6 // @include [url]http://www.garrysmod.org/*[/url] // @include [url]http://garrysmod.org/*[/url] // ==/UserScript== // // Original by aVoN - [url]http://39051.vs.webtropia.com/wordpress/[/url] // Rewritten by DfKimera - [url]http://www.dfkimera.com[/url] // // You are free to distribute,copy,delete :P,rewrite this piece of code even without giving credits. Have fun // var filename = document.getElementsByTagName("h2")[0].innerHTML; //The name of the file to download function str_replace(search, replace, subject, count) { // [url]http://kevin.vanzonneveld.net[/url] var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0, f = [].concat(search), r = [].concat(replace), s = subject, ra = r instanceof Array, sa = s instanceof Array; s = [].concat(s); if (count) { this.window[count] = 0; } for (i=0, sl=s.length; i < sl; i++) { if (s[i] === '') { continue; } for (j=0, fl=f.length; j < fl; j++) { temp = s[i]+''; repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0]; s[i] = (temp).split(f[j]).join(repl); if (count && s[i] !== temp) { this.window[count] += (temp.length-s[i].length)/f[j].length;} } } return sa ? s : s[0]; } //If someone set another title rather than the ZIP-File name, this script does not work! if(filename.indexOf(".zip") > 0){ var url = document.URL; //URL of this download var id = url.substr(url.indexOf("id")+3); // ID of this download var ForbiddenChars = new Array(" ","#"); // Mimics the way garrysmod.org filters forbidden chars on the file name. for(var i=0;i < ForbiddenChars.length;i++){ //filename = filename.replace(ForbiddenChars[i],"_"); filename = str_replace(ForbiddenChars[i], "_", filename); } // Base mirror URLs var new_url = "http://file.garrysmod.org"; // garrysmod.org var new_url_2 = "http://s3.garrysmod.org/files/"; // Amazon S3 // Forms URL for the garrysmod.org mirror for(var i = 0; i <= id.length; i++){ new_url += id.substr(i,1)+"/"; } new_url += filename; // Forms URL for the S3 mirror new_url_2 += id+"/"+filename.toLowerCase(); // Edits the information window to add the mirror links var temp = document.getElementById("TabWindow").innerHTML; var links = "<br><a href=\""+new_url+"\">[FAST] Try downloading from <b>file.garrysmod.org</b>"; links += "<br><a href=\""+new_url_2+"\">[FAST] Try downloading from <b>s3.garrysmod.org</b></a><br><br>"; // Replace info window with the modified version document.getElementById("TabWindow").innerHTML = links + temp; } [/cpp] Pastebin link ([url] BBcode-free): [url]http://pastebin.com/f29a1ded1[/url] Just like the old one, it will only work if the file name is in the title. I might try later to re-do this in order to try a XmlHttpRequest, fetch the link the site would try to use and serve the link without passing through Codeen; that would solve the file name issue. I'm not sure if this is infringing anything, if it is, I'm sorry. Just thought I'd share this piece with anyone and avoid the same frustration I used to have. [b]Edit: Forgot to close an <a> tag[/b] [b]Edit 2: V0.6: - Fixed issue with URLs containing space - Fixed issue on S3 with upper-case characters on the file name[/b]
sweet, installing it now yep, it's faster [editline]08:45PM[/editline] I suggest renaming the file in pastebin from .js.txt to .user.js just to make it so I don't have to download the text file, rename it, copy the location, paste it in firefox
I can't rename pastebin downloads, as far as I know. Did a little fix, forgot to close an <a> tag.
THANK YOU SO MUCH. GOD DAMN I HATED 0.5kByte/sec DOWNLOAD SPEEDS. :bang: [editline]04:56AM[/editline] Well I mean.. If it worked. [quote]//If someone set another title rather than the ZIP-File name, this script does not work![/quote] :frown: And I get alot of 404s for files that aren't renamed, and access denied for the S3 mirror.
There, I think I fixed that. Apparently, all S3 URLs are lowercase, and on both mirrors filenames with space are replaced with the underscore.
Thanks, there's a reason that Garry uses Codeen.
Whoo, thanks. The updated version works. [img]http://www.facepunch.com/fp/rating/heart.png[/img]
how do I install it to greasemonkey
Noob Question, how do I install this without a userscript link?
[QUOTE=Dacheet;16143352]Noob Question, how do I install this without a userscript link?[/QUOTE] [url=http://www.disorientation.co.uk/sirdigby/files/what.user.js]Click here to install the script.[/url]
[QUOTE=Dacheet;16143352]Noob Question, how do I install this without a userscript link?[/QUOTE] And I suppose you figuired it out all on your own without anyone telling you?
Sorry, you need to Log In to post a reply to this thread.