Last active
October 3, 2017 15:16
-
-
Save brianpow/5d88efaf69edebef1203b6d0d882853f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Download links' text beautifier | |
| var doc = (window.frames.length > 1) ? window.frames[2].document : document | |
| var jQuery = jQuery || window.frames[2].window.jQuery || null | |
| if (!jQuery) { | |
| var s = document.createElement('script'); | |
| s.setAttribute('src', 'http://code.jquery.com/jquery.js'); | |
| doc.body.appendChild(s); | |
| } else { | |
| (function($, doc) { | |
| var db = doc.body, | |
| all = [] | |
| function slugify(text) { | |
| return text.toString() //.toLowerCase() | |
| //.replace(/\s+/g, '-') // Replace spaces with - | |
| .replace(/[^\w\-\[\]\(\)\s\@\.,]+/g, '') // Remove all non-word chars | |
| .replace(/\s+/g, ' ') // Replace multiple - with single - | |
| //.replace(/^-+/, '') // Trim - from start of text | |
| //.replace(/-+$/, ''); // Trim - from end of text | |
| } | |
| $("tr", db).each(function(i) { | |
| a = $("a", this); | |
| if (a.length > 0 && a.text() == "Download") { | |
| title = $(this).find("b").text(); | |
| subtitle = $(this).find("b").next() | |
| element = [] | |
| date = "", orderNo = "", pages = "", language = "" | |
| while (subtitle.get(0).nextSibling && subtitle.get(0).nextSibling.data) { | |
| domElement = subtitle.get(0).nextSibling | |
| if (domElement.data.indexOf("Revision Date") != -1) | |
| date = domElement.data.replace("Revision Date ", "") | |
| else if (domElement.data.indexOf("Order Number") != -1) | |
| orderNo = domElement.data.replace("Order Number ", "").trim() | |
| else if (domElement.data && domElement.data.toString().match(/Pages/i)) | |
| pages = domElement.data | |
| else if (domElement.data) | |
| language = domElement.data.replace("only available in ", "") | |
| subtitle = subtitle.next() | |
| } | |
| if (language) { | |
| if (language[0] != "(") | |
| language = "(" + language + ")" | |
| title += " " + language; | |
| } | |
| if (pages) | |
| title += " " + pages + ""; | |
| if (date) { | |
| date = date.split("/") | |
| date = [date[2], date[1], date[0]].join("-") | |
| title += " [" + date + "]"; | |
| } | |
| filename = a.attr("href").replace(/.*\//g, "") | |
| ext = filename.match(/(\..*?)$/)[1] | |
| name = filename.match(/^(.*)\..+$/)[1] | |
| title = slugify(title) | |
| add(filename, name + " " + title + ext) | |
| a.html(title); | |
| } | |
| }) | |
| function add(oldName, newName) { | |
| if (!doc.getElementById("beautifier")) | |
| $("<textarea id=beautifier></textarea>").appendTo(doc.body) | |
| if (!doc.getElementById("uglifier")) | |
| $("<textarea id=uglifier></textarea>").appendTo(doc.body) | |
| doc.getElementById("beautifier").innerHTML += 'ren "' + oldName + '" "' + newName + '"' + "\n" | |
| doc.getElementById("uglifier").innerHTML += 'ren "' + newName + '" "' + oldName + '"' + "\n" | |
| } | |
| })(jQuery, doc) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment