// ==UserScript== // @name TPBSort // @namespace TPBSort // @grant tinysort // @require https://code.jquery.com/jquery-3.6.0.js // @include http*://thepiratebay.org/* // ==/UserScript== //console.log ("Entered TPBSort"); $('document').ready (function () { var scriptCode = new Array(); // this is where we are going to build our new script scriptCode.push('function sortlist (sr) {'); // scriptCode.push(' console.log ("click sr = " + sr);'); scriptCode.push(''); scriptCode.push(' if (sort_o[sr] == 1) {'); scriptCode.push(' tinysort.defaults.order = \'asc\';'); scriptCode.push(' sort_o[sr] = 0;'); scriptCode.push(' } else {'); scriptCode.push(' tinysort.defaults.order = \'desc\';'); scriptCode.push(' sort_o[sr] = 1;'); scriptCode.push(' }'); scriptCode.push(''); scriptCode.push(' if (sr == 5) {'); scriptCode.push(' tinysort("li#st", { selector: "input", attr: "value" });'); scriptCode.push(' return;'); scriptCode.push(' } else if (sr == 3) {'); // scriptCode.push(' console.log ("new sort ");'); scriptCode.push(' tinysort("li#st", { selector: "span:nth-child(" + sr + ")", forceStrings : true});'); scriptCode.push(' } else {'); scriptCode.push(' tinysort("li#st", "span:nth-child(" + sr + ")");'); scriptCode.push(' } '); scriptCode.push('}'); // now, we put the script in a new script element in the DOM var script = document.createElement('script'); // create the script element script.innerHTML = scriptCode.join('\n'); // add the script code to it scriptCode.length = 0; // recover the memory we used to build the script document.getElementsByTagName('head')[0].appendChild(script); // console.log ("script injected"); });