// ==UserScript==
// @name Multi-OCH Helper
// @namespace cuzi
// @oujs:author cuzi
// @description nopremium.pl and premiumize.me. Inserts a direct download link on several one-click-hosters and some container/folder providers.
// @homepageURL https://openuserjs.org/scripts/cuzi/Multi-OCH_Helper
// @icon https://greasyfork.org/system/screenshots/screenshots/000/003/479/original/icon.png
// @version 14.6
// @include /^https:\/\/cvzi\.github\.io\/Userscripts\/index\.html\?link=.+/
// @include /^https:\/\/www\.nopremium\.pl\/files.*$/
// @include /^https:\/\/www\.premiumize\.me\/services\/?$/
// @include /^https:\/\/www\.premiumize\.me\/downloader.*$/
// @include http://download.serienjunkies.org/*
// @include /^https?:\/\/(www\.)?filecrypt.cc\/Container\/\w+\.html.*$/
// @include http*filecrypt.cc/helper.html*
// @include /^http:\/\/www\.firedrive\.com\/share\/(\w|-)+$/
// @include http://linkcrypt.ws/dir/*
// @include http://linksave.in/*
// @include /^http:\/\/ncrypt\.in\/folder\-\w+$/
// @include http*://*uploaded.net/folder/*
// @include http*://*uploaded.net/f/*
// @include http*://rapidgator.net/folder/*
// @include http://www.relink.us/view.php?id=*
// @include https://safelinking.net/p/*
// @include http://linkshield.org/p/*
// @include http://share-links.biz/*
// @include http*://relink.to/view.php?id=*
// @include http://extreme-protect.net/*
// @include /^http:\/\/180upload\.com\/\w+$/
// @include /^https?:\/\/(www\.)?1fichier\.com\/\?.+$/
// @include /^https?:\/\/\w+\.1fichier\.com\/?.*$/
// @include /^http:\/\/www\.(2|4)shared\.com\/[a-z]+\/\w+\/?(.+\.html)?$/
// @include /^https?:\/\/(www\.)?alfafile\.net\/file\/.+$/
// @include /^https?:\/\/(www\.)?bayfiles\.(net|com)\/file\/\w+\/.+$/
// @include /^http:\/\/billionuploads\.com\/\w+$/
// @include /^http:\/\/bitshare\.com\/files\/\w+\/.+\.html$/
// @include /^https?:\/\/(www\.)?catshare\.net\/.+$/
// @include /^https?:\/\/www\.cwtv\.com\/cw-video\/.+$/
// @include /^http:\/\/www\.datafile\.com\/d\/\w+.*$/
// @include /^https?:\/\/www\.dailymotion\.com\/video\/\w+.*$/
// @include /^https?:\/\/(www\.)?devilshare\.net\/view\/\w+\/?.*$/
// @include http://filecloud.io/download.html
// @include /^http:\/\/filecloud\.io\/\w+(\/.*)?$/
// @include /^https?:\/\/(www\.)?filefactory\.com\/file\/.+$/
// @include /^http:\/\/(www\.)?filefactory\.com\/stream\/.+$/
// @include /^https?:\/\/www.filemonkey.in\/file\/.+$/
// @include /^https?:\/\/fileom\.com\/\w+.*$/
// @include /^https?\:\/\/(www\.)?fileparadox\.(in|com)\/\w+.*$/
// @include /^http:\/\/www\.firedrive\.com\/file\/\w+$/
// @include /^http:\/\/freakshare\.com\/files\/\w+\/.+\.html$/
// @include /^http:\/\/dl\.free\.fr\/\w+$/
// @include /^https?:\/\/(www\.)?gboxes\.com\/.+$/
// @include /^https?\:\/\/(www\.)?hitfile\.net\/\w+.*$/
// @include /^http:\/\/hugefiles\.net\/\w+\/?.*$/
// @include /^https?:\/\/www\.kingfiles\.net\/\w+.*$/
// @include /^https?:\/\/(\w+\.)?letitbit\.net\/download\/(\w|\.)+\/.*$/
// @include /^https?:\/\/www\.mediafire\.com\/?\?.+$/
// @include /^https?:\/\/www\.mediafire\.com\/download\/.+$/
// @include /^https?:\/\/mega\.co\.nz\/\#\!\w+!*(\w|-)*$/
// @include /^https?:\/\/mega\.nz\/\#\!\w+!*(\w|-)*$/
// @include /^https?:\/\/netload.in\/\w+\/(\w|-|\.)+$/
// @include /^https?:\/\/netload.in\/(\w|-|\.)+\.htm$/
// @include /^https?:\/\/www\.oboom\.com\/\w+.*$/
// @include /^https?:\/\/openload\.co\/f\/.+$/
// @include /^http:\/\/www\.pornhub\.com\/view_video\.php\?viewkey\=\w+$/
// @include /^http:\/\/rapidgator\.net\/file\/.+$/
// @include /^http:\/\/rg\.to\/file\/\w+\/.+\.html$/
// @include /^https?:\/\/(\w+\.)?rapidu\.net\/\w+.*$/
// @include /^http:\/\/www\.redtube\.com\/\d{1,10}$/
// @include /^http:\/\/www\.share-online\.biz\/dl\/\w+$/
// @include /^https?\:\/\/(www\.)?rockfile\.eu\/\w+.*$/
// @include /^http:\/\/www\.sockshare\.com\/file\/\w+$/
// @include /^https?:\/\/soundcloud.com\/(\w|-)+\/(\w|-)+$/
// @include /^https?:\/\/(www\.)?storbit\.net\/file\/.+$/
// @include /^http:\/\/streamcloud\.eu\/\w+$/
// @include /^https?:\/\/streamin\.to\/.+$/
// @include /^http:\/\/www\.tube8\.com\/.+\/\d+\/?$/
// @include /^http:\/\/turbobit\.net\/\w+.*\.html$/
// @include /^https?:\/\/(www\.)?tusfiles\.net\/\w+$/
// @include /^http:\/\/(www\.)?uploadboy\.com\/\w+\.html$/
// @include /^https?:\/\/uploaded\.(net|to)\/file\/.+$/
// @include /^http:\/\/(www\.)?uploading\.site\/\w+(\/.*)?\.htm$/
// @include /^http:\/\/uploadrocket\.net\/\w+(\/|\w|-|\.)+(\.html)?$/
// @include /^http:\/\/ul\.to\/.+$/
// @include /^http:\/\/uppit\.com\/\w+(\/.*)?$/
// @include /^http:\/\/uptobox.com\/\w+$/
// @include /^https?:\/\/vimeo\.com\/(.+\/)?\d+\/?$/
// @include /^http:\/\/\w+.vip-file\.com\/downloadlib\/.*$/
// @include /^http:\/\/www\.youporn\.com\/watch\/\d+\/.*$/
// @include /^https?:\/\/www\.youtube\.com\/watch(\?v=|\/).+$/
// @include /^http:\/\/xerver\.co\/\w+.*$/
// @include /^http:\/\/www\d*\.zippyshare\.com\/v\/\w+\/file\.html$/
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js
// @require https://greasyfork.org/scripts/13883-aes-js/code/aesjs.js
// @grant GM_registerMenuCommand
// @grant GM_xmlhttpRequest
// @grant GM_openInTab
// @grant GM_setClipboard
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @grant GM_listValues
// @grant unsafeWindow
// @downloadURL none
// ==/UserScript==
"use strict";
// And to keep for myself whatever I may find? - Certainly. For yourself, and any friends you want to share with you.
// This program inserts a download link on One-Click-Hosters and a few folder services.
// If you click on the button, the current website address (or the links on the relink website) will be sent to nopremium.pl and you'll receive a nopremium.pl download link.
//
// Standard actions for the button are
// * left mouse click: copy the link to the clipboard
// * middle/wheel click: start download of the link
// * right mouse click: open the nopremium.pl website and insert the link in the text box
// * hovering the mouse over the button: open a menu with all the above option
//
var s_myname = "Multi-OCH Helper";
var h_myname = "Multi-OCH Helper Highlight links";
var config = {
position : [["bottom","top"],["left","right"]],
position_desc : ['vertical','horizontal'],
position_quest : 'Position of the Button. If you use "'+h_myname+'" this has to be set to bottom left',
leftClick : ["clipboard","download","showLinks","openWebsite","menu","sendToJD","none"],
leftClick_desc : ["Copy link to clipboard","Direct download","Show links like on website","Open the multihoster website","Show the extended menu","Send links to JDownloader","Do nothing"],
leftClick_quest : "Action on left mouse click on button",
middleClick : ["download","clipboard","showLinks","openWebsite","menu","sendToJD","none"],
middleClick_desc : ["Direct download","Copy link to clipboard","Show links like on website","Open the multihoster website","Show the extended menu","Send links to JDownloader","Do nothing"],
middleClick_quest : "Action on middle mouse/wheel click on button",
rightClick : ["openWebsite","clipboard","showLinks","download","menu","sendToJD","none"],
rightClick_desc : ["Show links like on website","Copy link to clipboard","Direct download","Open the multihoster website","Show the extended menu","Send links to JDownloader","Do nothing"],
rightClick_quest : "Action on right mouse click on button",
mouseOver : ["menu","clipboard","download","showLinks","openWebsite","sendToJD","none"],
mouseOver_desc : ["Show the extended menu","Copy link to clipboard","Direct download","Show links like on website","Open the multihoster website","Send links to JDownloader","Do nothing"],
mouseOver_quest : "Action on mouse hover over button",
mouseOverDelay : 'int',
mouseOverDelay_range : [0,700,3000],
mouseOverDelay_quest : "Mouse hover time before action is executed.",
mouseOverDelay_suffix : "milliseconds",
newTab : 'bool',
newTab_desc : ["Open in a new tab","Open in the same window"],
newTab_quest : "Should websites be opened in a new tab?",
updateHosterStatusInterval : 'int',
updateHosterStatusInterval_range : [1,168,9999],
updateHosterStatusInterval_quest : "How often should the status of the hosters be updated?",
updateHosterStatusInterval_prefix : "Every",
updateHosterStatusInterval_suffix : "hours",
jDownloaderSupport : 'bool',
jDownloaderSupport_desc : ["Show JDownloader button if JDownloader is runnning","Never show JDownloader button"],
jDownloaderSupport_quest : ["Show a JDownloader button in the menu?"],
};
var settings = {};
// Load settings
var savedsettings = JSON.parse(GM_getValue("settings","{}")); // e.g. { position : [0,1], newTab : 1 }
for(var key in config) {
if(key in savedsettings) { // Saved
if(config[key] == 'int') { // Int
settings[key] = parseInt(savedsettings[key],10);
} else if(config[key] == 'bool') { // Bool
settings[key] = (savedsettings[key]=="true"||savedsettings[key]===true);
} else if(Array.isArray(savedsettings[key])) { // Nested array
settings[key] = [];
for(var i = 0; i < savedsettings[key].length; i++) {
settings[key].push(savedsettings[key][i]);
}
} else { // Array
settings[key] = savedsettings[key];
}
} else { // Default
if(config[key] == 'int') { // Int
settings[key] = config[key+"_range"][1];
}else if(config[key] == 'bool') { // Bool
settings[key] = true;
} else if(Array.isArray(config[key][0])) { // Nested array defaults to first value for each array
settings[key] = [];
for(var i = 0; i < config[key].length; i++) {
settings[key].push(config[key][i][0]);
}
} else {
settings[key] = config[key][0]; // Array defaults to first value
}
}
}
var JDOWNLOADER = "http://127.0.0.1:9666/";
var SHAREBIZ_CNL2_URL = "http://share-links.biz/get/cnl2/";
var SHAREBIZ_RSDF_URL = "http://share-links.biz/get/rsdf/";
var SHAREBIZ_DLC_URL = "http://share-links.biz/get/dlc/";
var DCRYPTIT_UPLOAD_URL = "http://dcrypt.it/decrypt/upload";
var DCRYPTIT_CONTAINERLINK_URL = "http://dcrypt.it/decrypt/container";
var POSATIV_URL = "http://posativ.org/decrypt/rsdf";
var RELINKUS_GETFILE = "http://www.relink.us/frame.php?";
var SPINNERCSS = "/* http://www.designcouch.com/home/why/2013/05/23/dead-simple-pure-css-loading-spinner/*/\
.ochspinner {\
height:16px;\
width:16px;\
margin:0px auto;\
position:relative;\
-webkit-animation: rotation .6s infinite linear;\
-moz-animation: rotation .6s infinite linear;\
-o-animation: rotation .6s infinite linear;\
animation: rotation .6s infinite linear;\
border-left:6px solid rgba(0,174,239,.15);\
border-right:6px solid rgba(0,174,239,.15);\
border-bottom:6px solid rgba(0,174,239,.15);\
border-top:6px solid rgba(0,174,239,.8);\
border-radius:100%;\
}\
@-webkit-keyframes rotation {\
from {-webkit-transform: rotate(0deg);}\
to {-webkit-transform: rotate(359deg);}\
}\
@-moz-keyframes rotation {\
from {-moz-transform: rotate(0deg);}\
to {-moz-transform: rotate(359deg);}\
}\
@-o-keyframes rotation {\
from {-o-transform: rotate(0deg);}\
to {-o-transform: rotate(359deg);}\
}\
\
@keyframes rotation {\
from {transform: rotate(0deg);}\
to {transform: rotate(359deg);}\
}\
";
var LOADINGBARBG = "background: #b4e391;\
background: -moz-linear-gradient(top, #b4e391 0%, #61c419 50%, #b4e391 100%);\
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#b4e391), color-stop(50%,#61c419), color-stop(100%,#b4e391));\
background: -webkit-linear-gradient(top, #b4e391 0%,#61c419 50%,#b4e391 100%);\
background: -o-linear-gradient(top, #b4e391 0%,#61c419 50%,#b4e391 100%);\
background: linear-gradient(to bottom, #b4e391 0%,#61c419 50%,#b4e391 100%);"
var show_oneclick_button = false;
var show_oneclick_link = "";
var show_oneclick_FromHighlighScript_allLinks = false;
var show_oneclick_FromHighlighScript_allLinks_loc = false;
var show_oneclick_FromHighlighScript_allLinks_links = "";
var show_oneclick_FromHighlighScript_selectedLinks = false;
var show_oneclick_FromHighlighScript_selectedLinks_loc = false;
var show_oneclick_FromHighlighScript_selectedLinks_links = "";
var links_beforeSelection = false;
var multi = {
'premiumize.me' : new (function() {
var self = this;
this.key = 'premiumize.me';
this.name = 'premiumize';
this.homepage = 'https://www.premiumize.me/';
this.status = JSON.parse(GM_getValue(this.key+"_status","{}"));
this.updateStatusURL = 'https://www.premiumize.me/services';
this.updateStatusURLpattern = /https:\/\/www\.premiumize\.me\/services\/?/;
this.lastUpdate = new Date(GM_getValue(this.key+"_status_time",0));
this.updateDownloadProgressInterval = 500;
this.updateStatus = function() { // Update list of online hosters
if(document.location.href.match(this.updateStatusURL)) {
// Read and save current status of all hosters
this.status = {};
$(".table.table-condensed tr>td:first-child").each(function() {
var text = $(this).text();
if(text.match(/^\s*[0-9a-z-]+\.\w{0,3}\s*$/)) {
var name = text.match(/^\s*([0-9a-z-]+)\.\w{0,3}\s*$/)[1];
self.status[name] = true;
}
});
GM_setValue(this.key+"_status",JSON.stringify(this.status));
GM_setValue(this.key+"_status_time",""+(new Date()));
} else {
alert(s_myname+"\n\nError: wrong update URL");
}
};
this.isOnline = function(hostername) {
return hostername in this.status && this.status[hostername];
};
this.getOpenWebsiteURL = function(urls) {
// Return a link to the premiumize.me website that will insert the links
var url = this.homepage+"downloader?link:"+encodeURIComponent(urls.join("\n"));
return url;
};
this.checkLink = function(url,cb) { // check whether the link is supported and online
var host = url.match(/https?:\/\/(.+?)\//)[1];
var hoster = host.split(".");
hoster.pop();
hoster = hoster.pop().replace("-","");
cb(this.isOnline(hoster));
};
this.getResults = function(urls,cb) {
// cb($node,linkNumber) -- $node contains the result, linkNumber is the number of links that should be online i.e. number of hashes
alert("This function does not work for "+this.name);
};
this._notLoggedIn = false;
this.getLinks = function(urls,cb) {
showConfirm("fairPointsWarning","You will be charged premiumize fair points for generating "+(urls.length>1?(""+urls.length+" files"):("one file"))+"!
Generate links?",function() { this._getLinks(urls, cb); },function() { setStatus("Operation canceled!",0); cb([],-1); },self);
};
this._getLinks = function(urls,cb) {
var N = urls.length;
var downloadLinks = [];
var errors = [];
for(var i = 0; i < urls.length; i++) {
this._getSingleLink(urls[i], function(downloadlink, originallink) {
if(downloadlink) {
downloadLinks.push(downloadlink);
} else {
errors.push(originallink);
}
});
}
var checkprogress = function() {
if(self._notLoggedIn) {
// Stop checking and open premiumize homepage
setStatus(self.name+" error: Not logged in!",0);
GM_openInTab(self.homepage);
cb([], -1);
return;
}
if(N == downloadLinks.length+errors.length) { // All finished
cb(downloadLinks);
if(errors.length > 0) { // Errors occured
alert("Errors occured\n"+errors.length+" links failed:\n\n"+errors.join("\n"));
}
} else { // not finished yet
window.setTimeout(checkprogress, self.updateDownloadProgressInterval);
}
};
window.setTimeout(checkprogress, 2*N*self.updateDownloadProgressInterval);
};
this._getSingleLink = function(url, cb) {
GM_xmlhttpRequest({
method: "POST",
url: self.homepage+"api/transfer/create",
data: "src="+encodeURIComponent(url)+"&seed=2or48h",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Cache-Control" : "no-cache",
"Referer" : "https://www.premiumize.me/downloader"
},
onerror: function(response) {
console.log("GM_xmlhttpRequest error: "+self.homepage+"api/transfer/create");
console.log(response);
cb(false, url);
},
onload: function(response) {
var result = JSON.parse(response.responseText);
if(result["status"] != "success") {
if("message" in result && !self._notLoggedIn) {
setStatus(result["message"],-1);
if(~result["message"].indexOf("log")) {
self._notLoggedIn = true;
}
}
cb(false, url);
} else {
cb(result.location, url);
}
}
});
};
})(),
'nopremium.pl' : new (function() {
var self = this;
this.config = {
'mode' : ['transfer','premium','none'],
'mode_desc' : ['Transfer User (Pakiety Transferowe)','Premium User (Konta Premium)','No account'],
'mode_quest' : 'What kind of account do you have at nopremium.pl',
'downloadmode' : ['direct','server'],
'downloadmode_desc' : ['Direct download (TRYB SZYBKIEGO POBIERANIA)','Downloading via NoPremium.pl server (TRYB POBIERANIA NA SERWERY)'],
'downloadmode_quest' : ['Which download mode do you want to use?']
};
this.key = 'nopremium.pl';
this.name = 'NoPremium.pl';
this.homepage = 'https://www.nopremium.pl/';
this.status = JSON.parse(GM_getValue(this.key+"_status","{}"));
var mapHosterName = function(name) {return name.replace("-","")};
this.updateStatusURL = 'https://www.nopremium.pl/files';
this.updateStatusURLpattern =/https?:\/\/www\.nopremium\.pl\/files\/?/;
this.lastUpdate = new Date(GM_getValue(this.key+"_status_time",0));
this.updateDownloadProgressInterval = 5000;
this.settings = {};
this.loadSettings = function() {
// Load settings, use first value as default
var savedsettings = JSON.parse(GM_getValue(this.key+"_settings","{}"));
for(var key in this.config) {
if(key.endsWith("desc") || key.endsWith("range") || key.endsWith("quest") || key.endsWith("prefix") || key.endsWith("suffix")) {
continue;
}
if(key in savedsettings) { // Saved
if(this.config[key] == 'int') { // Int
this.settings[key] = parseInt(savedsettings[key],10);
}else if(config[key] == 'bool') { // Bool
this.settings[key] = savedsettings[key]=="true"||savedsettings[key]===true;
} else if(Array.isArray(savedsettings[key])) { // Nested array
this.settings[key] = [];
for(var i = 0; i < savedsettings[key].length; i++) {
this.settings[key].push(savedsettings[key][i]);
}
} else { // Array
this.settings[key] = savedsettings[key];
}
} else { // Default
if(this.config[key] == 'int') { // Int
this.settings[key] = this.config[key+"_range"][1];
} else if(config[key] == 'bool') { // Bool
this.settings[key] = true;
} else if(Array.isArray(this.config[key][0])) { // Nested array defaults to first value for each array
this.settings[key] = [];
for(var i = 0; i < this.config[key].length; i++) {
this.settings[key].push(this.config[key][i][0]);
}
} else {
this.settings[key] = this.config[key][0]; // Array defaults to first value
}
}
}
};
this.loadSettings(); // Load settings
this.updateStatus = function() { // Update list of online hosters
if(document.location.href.match(this.updateStatusURL)) {
// Read and save current status of all hosters
this.status = {};
$("#servers a[title]").each(function() {
var name = mapHosterName(this.title);
self.status[name] = true;
});
GM_setValue(this.key+"_status",JSON.stringify(this.status));
GM_setValue(this.key+"_status_time",""+(new Date()));
} else {
alert(s_myname+"\n\nError: wrong update URL");
}
};
this.isOnline = function(hostername) {
return hostername in this.status && this.status[hostername];
};
this.getOpenWebsiteURL = function(urls) {
// Return a link to the nopremium.pl website that will insert the links
var url = this.homepage+"files?link:"+encodeURIComponent(urls.join("\n"));
return url;
};
var getHashs = function(urls,cb,silent) {
// cb(hashes,sizestring)
setStatus("Sending "+(urls.length===1?"one link":(urls.length+" links")),-1);
GM_xmlhttpRequest({
method: "POST",
url: self.homepage+"files",
data: "watchonline=&session="+(Math.round(Math.random()*1234567))+"&links="+encodeURIComponent(urls.join("\n")),
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Cache-Control" : "no-cache",
"Referer" : "https://www.nopremium.pl/files"
},
onload: function(response) {
if(response.responseText.indexOf('') != -1) {
setStatus(self.name+" error: Not logged in!",0);
GM_openInTab(self.homepage);
return cb([],-1);
}
var hashes = [];
// Find hashes
var re = /name\=\"hash(\d+)\" value\=\"(\w+)\"/g; //
size = ma[1]+" "+ma[2];
}
setStatus(self.name+" identified "+(hashes.length===1?"one online file":(hashes.length+" online files")),-1);
cb(hashes,size);
}
});
};
this.checkLink = function(url,cb) { // check whether the link is supported and online
// cb(boolresult)
return getHashs([url],function(hashes,size) {
cb(hashes.length === 1);
},true);
};
this.getResults = function(urls,cb,hashes) {
// cb($node,linkNumber) -- $node contains the result, linkNumber is the number of links that should be online i.e. number of hashes
// Get download links from nopremium.pl and show the usual info about the file, that is normally shown on nopremium.pl
if(typeof hashes == "undefined") {
// 1. Get hashes and show transfer warning
getHashs(urls,function(hashes,size) {
if(settings.mode == 'transfer') {
showConfirm("transferWarning","You will be charged "+size+" 'Transfer' for generating "+(hashes.length>1?(""+hashes.length+" files"):("one file"))+"!
Generate links?",function() { this.getResults(urls,cb,hashes); },null,self);
} else if(hashes.length > 0) {
self.getResults(urls,cb,hashes);
} else if(size === -1) { // Error was already handled (probably not logged in)
cb(false,0);
} else { // No files found
setStatus("No online/available files",0);
cb(false,0);
}
});
return;
}
// 2. Work with hashes
var $resultContainer = $("
").appendTo($form);
if(c[key+"_quest"]) {
$p.append(c[key+"_quest"]);
} else {
$p.append(key);
}
$p.append("
");
if(c[key+"_prefix"]) {
$p.append(c[key+"_prefix"]+" ");
}
if(c[key] == 'int') { // Int
var $input = $('').addClass("form_"+formid).data("key",key).data("parse","int").val(s[key]).appendTo($p);
if(c[key+"_range"]) {
$input.prop("min",c[key+"_range"][0]);
$input.prop("max",c[key+"_range"][2]);
$input.prop("title",c[key+"_range"][0]+" - "+c[key+"_range"][2]);
}
} else if(c[key] == 'bool') { // Bool
var $select = $('').addClass("form_"+formid).data("key",key).data("parse","bool").appendTo($p);
var $optionYes = $('').val("true").appendTo($select);
if(c[key+"_desc"]) {
$optionYes.html(c[key+"_desc"][0]);
} else {
$optionYes.html("Yes");
}
if(s[key]) {
$optionYes[0].selected = true;
}
var $optionNo = $('').val("false").appendTo($select);
if(c[key+"_desc"]) {
$optionNo.html(c[key+"_desc"][1]);
} else {
$optionNo.html("No");
}
if(!s[key]) {
$optionNo[0].selected = true;
}
} else if(Array.isArray(c[key][0])) { // Nested array
for(var j = 0; j < c[key].length; j++) {
if(c[key+"_desc"] && !Array.isArray(c[key+"_desc"][j])) {
$p.append(c[key+"_desc"][j]+": ");
}
var $select = $('').addClass("form_"+formid).data("key",key).data("index",j).appendTo($p);
for(var i = 0; i < c[key][j].length; i++) {
var $option = $('').val(c[key][j][i]).appendTo($select);
if(c[key+"_desc"] && Array.isArray(c[key+"_desc"][0])) {
$option.html(c[key+"_desc"][j][i]);
} else {
$option.html(c[key][j][i]);
}
if(s[key][j] == c[key][j][i])
$option[0].selected = true;
}
$p.append("
");
}
} else { // Array
var $select = $('').addClass("form_"+formid).data("key",key).appendTo($p);
for(var i = 0; i < c[key].length; i++) {
var $option = $('').val(c[key][i]).appendTo($select);
if(c[key+"_desc"]) {
$option.html(c[key+"_desc"][i]);
} else {
$option.html(c[key][i]);
}
if(s[key] == c[key][i])
$option[0].selected = true;
}
}
if(c[key+"_suffix"]) {
$p.append(" "+c[key+"_suffix"]);
}
}
}
function saveSettings(ev) {
var $body = ev.data;
var $form = $body.find(".form");
// Save preferred hoster:
currentdebrid = $form.find('.debridhoster').val();
// Save options:
var newsettings = { 'general' : {} };
for(var key in multi) {
newsettings[key] = {};
}
$form.find('*[class^=form_]').each(function() {
var $this = $(this);
var namespace = $this.prop("class").split("_",2)[1];
var key = $this.data("key");
var index = $this.data("index");
var value = $this.val();
var parse = $this.data("parse");
if(typeof index != 'undefined') { // Nested Array
if(!Array.isArray(newsettings[namespace][key])) {
newsettings[namespace][key] = [];
}
newsettings[namespace][key][index] = value;
} else { // Normal
if(parse == 'int') {
value = parseInt(value,10);
} else if(parse == 'bool') {
value = (value == "true");
}
newsettings[namespace][key] = value;
}
});
GM_setValue("setup",true);
GM_setValue("currentdebrid",currentdebrid);
GM_setValue("settings",JSON.stringify(newsettings.general));
for(var key in multi) {
GM_setValue(key+"_settings",JSON.stringify(newsettings[key]));
}
alert(s_myname+"\n\nSettings were successfully saved!");
document.location.reload();
}
function aboutMe() {
var popup = popUp("multiochhelper_about",null,null,true);
var $popup = popup.node;
var $frame = $('