// ==UserScript== // @name APOLLO :: Collage Building Helper // @author Z4ppy // @namespace Z4ppy.What.CD // @description Make it easier to build your collage. // @include https://*apollo.rip/torrents.php* // @include https://*apollo.rip/collages.php* // @include https://*apollo.rip/collage.php* // @include https://*apollo.rip/artist.php* // @include https://*apollo.rip/bookmarks.php* // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // @grant GM_registerMenuCommand // @grant GM_xmlhttpRequest // @version 1.0.1 // @date 2013-03-05 // @downloadURL none // ==/UserScript== var collageID, collName; // Momenticons: http://findicons.com/icon/263495/folder_open_add var ICON_ADD = 'http://i.imgur.com/snd3Doj.png='; // Yusuke Kamiyamane: http://findicons.com/icon/118036/cross var ICON_ERR = 'http://i.imgur.com/djo7YFS.png='; // Yusuke Kamiyamane: http://findicons.com/icon/119015/tick var ICON_OK = 'http://i.imgur.com/jCdKolj.png'; // ajaxload.info var ICON_LOADING = 'data:image/gif;base64,R0lGODlhEAAQAPIAAP///wAAAMLCwkJCQgAAAGJiYoKCgpKSkiH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCgAAACwAAAAAEAAQAAADMwi63P4wyklrE2MIOggZnAdOmGYJRbExwroUmcG2LmDEwnHQLVsYOd2mBzkYDAdKa+dIAAAh+QQJCgAAACwAAAAAEAAQAAADNAi63P5OjCEgG4QMu7DmikRxQlFUYDEZIGBMRVsaqHwctXXf7WEYB4Ag1xjihkMZsiUkKhIAIfkECQoAAAAsAAAAABAAEAAAAzYIujIjK8pByJDMlFYvBoVjHA70GU7xSUJhmKtwHPAKzLO9HMaoKwJZ7Rf8AYPDDzKpZBqfvwQAIfkECQoAAAAsAAAAABAAEAAAAzMIumIlK8oyhpHsnFZfhYumCYUhDAQxRIdhHBGqRoKw0R8DYlJd8z0fMDgsGo/IpHI5TAAAIfkECQoAAAAsAAAAABAAEAAAAzIIunInK0rnZBTwGPNMgQwmdsNgXGJUlIWEuR5oWUIpz8pAEAMe6TwfwyYsGo/IpFKSAAAh+QQJCgAAACwAAAAAEAAQAAADMwi6IMKQORfjdOe82p4wGccc4CEuQradylesojEMBgsUc2G7sDX3lQGBMLAJibufbSlKAAAh+QQJCgAAACwAAAAAEAAQAAADMgi63P7wCRHZnFVdmgHu2nFwlWCI3WGc3TSWhUFGxTAUkGCbtgENBMJAEJsxgMLWzpEAACH5BAkKAAAALAAAAAAQABAAAAMyCLrc/jDKSatlQtScKdceCAjDII7HcQ4EMTCpyrCuUBjCYRgHVtqlAiB1YhiCnlsRkAAAOwAAAAAAAAAAAA=='; var torrentCache = { Cache: [], GM_read: function () { this.clear(); this.Cache = JSON.parse(GM_getValue('torrentCache', '[]')); return this.Cache.length; }, GM_save: function () { return GM_setValue('torrentCache', JSON.stringify(this.Cache)); }, GM_delete: function () { GM_deleteValue('torrentCache'); }, add: function (torrentgroupid) { if (this.Cache.indexOf(torrentgroupid) != -1) { return false; } this.Cache.push(torrentgroupid); return true; }, contains: function (torrentgroupid) { return (this.Cache.indexOf(torrentgroupid) != -1); }, remove: function (torrentgroupid) { if (this.Cache.indexOf(torrentgroupid) == -1) { return false; } this.Cache.splice(this.Cache.indexOf(torrentgroupid), 1); return true; }, clear: function () { this.Cache.length = 0; } } var URL = new Object(); function parseURL() { var URLArr = document.URL.match(/^(https:\/\/(?:ssl\.)?apollo\.rip)\/([\w\/\.]+?)(\?(.*?))?(#.*)?$/); URL.Host = URLArr[1]; //protocol + hostname, eg. https://apollo.rip URL.Path = URLArr[2]; URL.Hash = URLArr[5]; URL.Parameters = new Object(); if (typeof URLArr[4] != 'undefined') { var URLPArr = URLArr[4].split('&'); //URL parameter array var tmpP; //temporary Parameter for (var i = 0; i < URLPArr.length; ++i) { tmpP = URLPArr[i].split('='); URL.Parameters[tmpP[0]] = tmpP[1]; } } } function init() { parseURL(); getCollageID(); torrentCache.GM_read(); // putting the add image on various pages (with an active collage) // $.inArray(URL.Path, ['torrents.php', 'artist.php']) if ((URL.Path == 'torrents.php' || URL.Path == 'artist.php' || URL.Path == 'bookmarks.php' || URL.Path == 'collages.php') && (collageID != 0)) { if (URL.Path == 'torrents.php' && URL.Parameters['id']) { //torrent group page var title = document.getElementById('content').getElementsByTagName('h2')[0]; title.insertBefore(document.createTextNode(' '), null); title.insertBefore(createAddIcon(URL.Host + '/torrents.php?id=' + URL.Parameters['id'], URL.Parameters['id']), null); } else { var tableId = ''; if (URL.Path == 'torrents.php' && (URL.Parameters['type'] || URL.Parameters['action'] == 'notify')) { // user uploaded/snatched/etc and notifications tableId = 'content'; } else if (URL.Path == 'artist.php' || (URL.Path == 'collages.php' && URL.Parameters['id'] && URL.Parameters['id'] != collageID)) { // artist page; other collages tableId = 'discog_table'; } else if (URL.Path == 'torrents.php' || URL.Path == 'bookmarks.php') { // search page; bookmarks tableId = 'torrent_table'; } if (tableId != '') { var linkArr = extractTorrentgroupLinks(tableId); for (var i = 0; i < linkArr.length; ++i) { linkArr[i].parentNode.insertBefore(document.createTextNode(' '), linkArr[i].parentNode.firstChild); linkArr[i].parentNode.insertBefore(createAddIcon(linkArr[i].href, linkArr[i].getAttribute('torrentgroupid')), linkArr[i].parentNode.firstChild); } } } } if (URL.Path == 'collages.php' && URL.Parameters['id'] && !URL.Parameters['action']) { var currentCollURL = URL.Parameters['id']; var cx = document.getElementsByTagName('h2')[0]; if (collageID != 0 && collageID != currentCollURL) { // if there is an active collage & the active collage is different than current page, use name + link cx.parentNode.innerHTML = "\
')+3); description = description.substring(0, description.search('
')); img.src = ICON_ERR; alert(title+"\n\n"+description); } else { // Remember: inCollage is determined *before* sending the request. When inCollage is true, the torrent now isn't in the collage anymore! if (inCollage) { torrentCache.remove(img.getAttribute('torrentgroupid')); } else { torrentCache.add(img.getAttribute('torrentgroupid')); } torrentCache.GM_save(); updateAddIcon(img); } }, onerror: function(f) { img.src = ICON_ERR; alert('Some unknown error occured. Refresh the page and try again!'); } }); } function manage_remove_click(e) { torrentCache.remove(e.target.getAttribute('torrentgroupid')); torrentCache.GM_save(); return true; } //find authkey function findAuthKey() { return unsafeWindow.authkey; } // preference for always showing checkboxes on manage page GM_registerMenuCommand("Apollo.rip :: Collage Building Helper - MathRange checkboxes", function() { var checkBoxQuestion; for (var zz = 1; zz <= 3 && isNaN(checkBoxQuestion); ++zz) { checkBoxQuestion = prompt("Do you want the checkboxes to always appear on the manage collage page?\nType \"1\" for yes and \"0\" for no.\nCurrent selection is: " + GM_getValue("checkBoxAlwaysOn", "0") + " (0 is default)"); if (checkBoxQuestion != null && checkBoxQuestion != '') { checkBoxQuestion = parseInt(checkBoxQuestion); if (isNaN(checkBoxQuestion)) { if (zz==3) { alert("Try harder! Better luck next time!"); } else { alert("Please pick \"1\" or \"0\" (no quotes)"); } } else if (checkBoxQuestion == 0 || checkBoxQuestion == 1) { GM_setValue("checkBoxAlwaysOn", checkBoxQuestion); } else { alert("Please pick \"1\" or \"0\" (no quotes)"); } } } }); init();