// ==UserScript==
// @name Multi-OCH Helper
// @namespace cuzi
// @license MIT
// @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 16.1
// @include /^https:\/\/cvzi\.github\.io\/Userscripts\/index\.html\?link=.+/
// @include /^https:\/\/www\.nopremium\.pl\/files.*$/
// @include /^https:\/\/www\.premiumize\.me\/hosters\/?$/
// @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 /^https?:\/\/(www\.)?1fichier\.com\/.+$/
// @include /^https?:\/\/\w+\.1fichier\.com\/?.*$/
// @include /^http:\/\/www\.4shared\.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 /^https?:\/\/(www\.)?catshare\.net\/.+$/
// @include /^https?:\/\/(www\.)?clicknupload\.(link|org)\/\w+\/?.*$/
// @include /^https?:\/\/(www\.)?datei\.to\/\?\w+$/
// @include /^https?:\/\/(www\.)?ddl\.to\/\w+$/
// @include /^https?:\/\/(www\.)?devilshare\.net\/view.+$/
// @include /^https?:\/\/(www\.)?file\.al\/\w+\/?.*$/
// @include /^https?:\/\/(www\.)?filefactory\.com\/file\/.+$/
// @include /^https?:\/\/www.filemonkey.in\/file\/.+$/
// @include /^https:\/\/filer\.net\/get\/\w+$/
// @include /^https?:\/\/(www\.)?filespace\.com\/\w+\/?$/
// @include /^https?:\/\/filestore\.to\/\?d=\w+$/
// @include /^http:\/\/www\.firedrive\.com\/file\/\w+$/
// @include /^https?:\/\/fireget\.com\/\w+\/?.*$/
// @include /^https?\:\/\/(www\.)?hitfile\.net\/\w+.*$/
// @include /^https?\:\/\/(www\.)?hil\.to\/\w+.*$/
// @include /^http:\/\/hugefiles\.net\/\w+\/?.*$/
// @include /^https:\/\/isra\.cloud\/\w+\/?.*$/
// @include /^https?:\/\/katfile\.com\/\w+\/?.*$/
// @include /^https?:\/\/lunaticfiles\.com\/\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?:\/\/modsbase\.com\/\w+\/?.*$/
// @include /^https?:\/\/openload\.co\/f\/.+$/
// @include /^https?:\/\/rapidgator\.net\/file\/[^#]+$/
// @include /^https?:\/\/rg\.to\/file\/[^#]+$/
// @include /^https?:\/\/(\w+\.)?rapidu\.net\/\w+.*$/
// @include /^https?\:\/\/(www\.)?rockfile\.(eu|co)\/\w+.*$/
// @include /^http:\/\/www\.sockshare\.com\/file\/\w+$/
// @include /^https?:\/\/(www\.)?storbit\.net\/file\/.+$/
// @include /^https?:\/\/(www\.)?spicyfile\.com\/\w+$/
// @include /^https?:\/\/streamin\.to\/.+$/
// @include /^https?:\/\/turbobit\.net\/\w+.*\.html$/
// @include /^https?:\/\/(www\.)?tusfiles\.net\/\w+$/
// @include /^https?:\/\/ubiqfile\.com\/\w+$/
// @include /^https?:\/\/uploadboy\.(me|com)\/\w+\/?.*$/
// @include /^https?:\/\/uploaded\.(net|to)\/file\/.+$/
// @include /^http:\/\/ul\.to\/.+$/
// @include /^https?:\/\/uploadgig\.com\/file\/download\/\w+\/?.*$/
// @include /^http:\/\/uploading\.com\/\w+\/?.*$/
// @include /^http:\/\/(www\.)?uploading\.site\/\w+.*$/
// @include /^http:\/\/uploadrocket\.net\/\w+(\/|\w|-|\.)+(\.html)?$/
// @include /^http:\/\/uptobox.com\/\w+(\/.*)?$/
// @include /^https?:\/\/userscloud\.com\/\w+.*$/
// @include /^https?:\/\/vidto\.me\/\w+\.?\w*$/
// @include /^https?:\/\/www\.wdupload\.com\/file\/\w+\/?.*$/
// @include /^https?:\/\/worldbytez\.com\/\w+$/
// @include /^https?:\/\/(www\.)?xubster\.com\/\w+\/?.*$/
// @include /^https?:\/\/www\.youtube\.com\/watch(\?v=|\/).+$/
// @include /^http:\/\/www\d*\.zippyshare\.com\/v\/\w+\/file\.html$/
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
// @require https://greasyfork.org/scripts/13883-aes-js/code/aesjs.js
// @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
// @grant GM_registerMenuCommand
// @grant unsafeWindow
// @grant GM_xmlhttpRequest
// @grant GM_openInTab
// @grant GM_setClipboard
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @grant GM_listValues
// @grant GM.xmlHttpRequest
// @grant GM.openInTab
// @grant GM.setClipboard
// @grant GM.setValue
// @grant GM.getValue
// @grant GM.deleteValue
// @grant GM.listValues
// @downloadURL none
// ==/UserScript==
(async function() {
"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 s_referer = "multiochhelper";
var h_myname = "Multi-OCH Helper Highlight links";
var chrome = ~navigator.userAgent.indexOf("Chrome")
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(await 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] == 'string') { // String
settings[key] = savedsettings[key].toString()
} else if(config[key] == 'bool') { // Bool
settings[key] = (savedsettings[key]=="true"||savedsettings[key]===true);
} else if(Array.isArray(config[key][0])) { // Nested array
if (!Array.isArray(savedsettings[key])) {
try {
const tmp = JSON.parse(savedsettings[key])
if(Array.isArray(tmp)) {
savedsettings[key] = tmp
}
} catch(e) {}
}
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] == 'string') { // String
settings[key] = '' // String defaults to empty string
} 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;\
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%;\
}\
@keyframes rotation {\
from {transform: rotate(0deg)}\
to {transform: rotate(359deg)}\
}\
";
var LOADINGBARBG = "background: #b4e391;\
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 = document.location.host == "cvzi.github.io";
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.config = {
'apikey' : 'string',
'apikey_quest' : 'Enter your premiumize.me API key',
'apikey_prefix' : 'API key: ',
'apikey_suffix' : ' find it under https://www.premiumize.me/account'
};
this.key = 'premiumize.me';
this.name = 'premiumize';
this.homepage = 'https://www.premiumize.me/';
this.updateStatusURL = 'https://www.premiumize.me/hosters';
this.updateStatusURLpattern = /https:\/\/www\.premiumize\.me\/hosters\/?/;
this.updateDownloadProgressInterval = 5000;
this.updateDownloadProgressInterfaceInterval = 500;
this.status = {};
this.init = async function() {
self.status = JSON.parse(await GM.getValue(self.key+"_status","{}"));
self.lastUpdate = new Date(await GM.getValue(self.key+"_status_time",0));
};
this.settings = {};
this.loadSettings = async function(silent) {
// Load settings, use first value as default
var savedsettings = JSON.parse(await GM.getValue(self.key+"_settings","{}"));
for(var key in self.config) {
if(key.endsWith("desc") || key.endsWith("range") || key.endsWith("quest") || key.endsWith("prefix") || key.endsWith("suffix")) {
continue;
}
if(key in savedsettings) { // Saved
if(self.config[key] == 'int') { // Int
self.settings[key] = parseInt(savedsettings[key],10);
} else if(self.config[key] == 'string') { // String
self.settings[key] = savedsettings[key].toString();
} else if(config[key] == 'bool') { // Bool
self.settings[key] = savedsettings[key]=="true"||savedsettings[key]===true;
} else if(Array.isArray(savedsettings[key])) { // Nested array
self.settings[key] = [];
for(var i = 0; i < savedsettings[key].length; i++) {
self.settings[key].push(savedsettings[key][i]);
}
} else { // Array
self.settings[key] = savedsettings[key];
}
} else { // Default
if(self.config[key] == 'int') { // Int
self.settings[key] = self.config[key+"_range"][1];
} else if(self.config[key] == 'string') { // String
self.settings[key] = ''; // String defaults to empty string
} else if(config[key] == 'bool') { // Bool
self.settings[key] = true;
} else if(Array.isArray(self.config[key][0])) { // Nested array defaults to first value for each array
self.settings[key] = [];
for(var i = 0; i < self.config[key].length; i++) {
self.settings[key].push(self.config[key][i][0]);
}
} else {
self.settings[key] = self.config[key][0]; // Array defaults to first value
}
}
}
if(!self.settings.apikey && !silent) {
// Try to get the apikey from the website
GM.xmlHttpRequest({
method: "GET",
url: self.homepage+"account",
onerror: function(response) {
console.log(s_myname+": premiumize.me API Key could not be loaded")
setStatus('You have not set you premiumize.me Api key ')
},
onload: function(response) {
let s = ''
try {
s = response.responseText.split('class="apipass"')[1].split('')[0].split('>')[1]
} catch(e) {
}
if (s) {
self.settings.apikey = s
GM.setValue(self.key+"_settings", JSON.stringify(self.settings));
console.log(s_myname+": premiumize.me API Key was loaded from account and saved!")
} else {
setStatus('You need to set you premiumize.me Api key')
}
}
});
}
};
this.updateStatus = async function() { // Update list of online hosters
if(document.location.href.match(self.updateStatusURL)) {
// Read and save current status of all hosters
self.status = {};
$("table.table tr>td:first-child").each(function() {
var text = $(this).text();
if(text.match(/^\s*[0-9a-z-]+\.\w{0,6}\s*$/i)) {
var name = text.match(/^\s*([0-9a-z-]+)\.\w{0,6}\s*$/i)[1];
self.status[name.toLowerCase()] = true;
}
});
await GM.setValue(self.key+"_status",JSON.stringify(self.status));
await GM.setValue(self.key+"_status_time",""+(new Date()));
console.log(s_myname+": "+self.name+": Hosters ("+Object.keys(self.status).length+") updated");
} else {
alert(s_myname+"\n\nError: wrong update URL");
}
};
this.isOnline = function(hostername) {
return hostername in self.status && self.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 = async function(urls,cb) {
await showConfirm("fairPointsWarning","You will be charged premiumize fair points for generating "+(urls.length>1?(""+urls.length+" files"):("one file"))+"!
Generate links?",function() { self._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._addSingleTransfer(urls[i], function(downloadlink, originallink, message) {
if(downloadlink) {
downloadLinks.push(downloadlink);
} else {
errors.push([originallink, message]);
}
});
}
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 == errors.length) { // All errors
cb(false, -1);
if (errors.length == 1 && errors[0][1]) {
setStatus(errors[0][1], 0);
} else {
alert("Errors occured\n"+errors.length+" links failed:\n\n"+errors.join("\n"));
}
} else 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.updateDownloadProgressInterfaceInterval);
}
};
window.setTimeout(checkprogress, self.updateDownloadProgressInterfaceInterval * Math.max(5, N));
};
this._addSingleTransfer = function(url, cb) {
GM.xmlHttpRequest({
method: "POST",
url: self.homepage+"api/transfer/create",
data: "apikey="+encodeURIComponent(self.settings.apikey)+"&src="+encodeURIComponent(url),
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Cache-Control" : "no-cache"
},
onerror: function(response) {
console.log(s_myname+": GM.xmlHttpRequest error: "+self.homepage+"api/transfer/create");
console.log(response);
cb(false, url, 'GM.xmlHttpRequest error: api/transfer/create');
},
onload: function(response) {
var result = JSON.parse(response.responseText);
/*
{"status":"success","type":"savetocloud","id":"gfwRtdgd5fgdfgfhgfhf","name":"test.zip"}
{"status":"error","error":"duplicate","id":"gfdgd5fgFddfgfhgfhf","message":"You already have this job added."}
{"status":"error","message":"This link is not available on the file hoster website"}
*/
if("id" in result && result.id) {
window.setTimeout(function() {
self._getFileFromTransfer(url, result.id, cb)
}, 1000)
if("message" in result) {
addStatus(result["message"],-1);
}
} else {
if("message" in result && !self._notLoggedIn) {
addStatus(result["message"],-1);
if(~result["message"].indexOf("log")) {
self._notLoggedIn = true;
}
}
cb(false, url, "message" in result?result["message"]:response.responseText);
}
}
});
};
this._getFileFromTransfer = function(url, transferId, cb) {
GM.xmlHttpRequest({
method: "GET",
url: self.homepage+"api/transfer/list?apikey=" + encodeURIComponent(self.settings.apikey),
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Cache-Control" : "no-cache"
},
onerror: function(response) {
console.log(s_myname+": GM.xmlHttpRequest error: "+self.homepage+"api/transfer/list");
console.log(response);
cb(false, url, "GM.xmlHttpRequest error: /api/transfer/list");
},
onload: function(response) {
var result = JSON.parse(response.responseText);
/*
{
"status": "success",
"transfers": [
{
"id": "xXFDSXXFDSGD",
"name": "test.zip",
"message": null,
"status": "finished",
"progress": 0,
"folder_id": "gfjdfsuigjfdoikfsadf",
"file_id": "trhgf982u30fjklfsdag"
}
]
}
{
"status": "success",
"transfers": [
{
"id":"xXFDSXXFDSGD",
"name":"test.zip",
"message":"Initializing Download...",
"status":"running",
"progress":0,
"folder_id":"gfjdfsuigjfdoikfsadf",
"file_id":null
}
]
}
*/
if(result.status == "success" && "transfers" in result) {
for(let i = 0; i < result.transfers.length; i++) {
if (result.transfers[i].id == transferId) {
if (result.transfers[i].file_id) {
// Finished
window.setTimeout(function() {
self._getSingleLink(url, result.transfers[i].file_id, cb)
}, result.transfers[i].status == "finished"?10:self.updateDownloadProgressInterval)
} else {
// Downloading
if('message' in result.transfers[i] && result.transfers[i].message) {
setStatus(result.transfers[i].message,-1);
}
window.setTimeout(function() {
self._getFileFromTransfer(url, transferId, cb)
}, self.updateDownloadProgressInterval)
}
return
}
}
}
if('message' in result && result.message) {
alert(s_myname+'\n\nCould not get /api/transfer/list\nError:\n'+result.message)
}
cb(false, url, 'Could not find url in transfer list');
}
});
};
this._getSingleLink = function(url, fileId, cb) {
GM.xmlHttpRequest({
method: "POST",
url: self.homepage+"api/item/details",
data: "apikey="+encodeURIComponent(self.settings.apikey)+"&id="+encodeURIComponent(fileId),
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Cache-Control" : "no-cache"
},
onerror: function(response) {
console.log(s_myname+": GM.xmlHttpRequest error: "+self.homepage+"api/item/details");
console.log(response);
cb(false, url, "GM.xmlHttpRequest error: /api/item/details");
},
onload: function(response) {
var result = JSON.parse(response.responseText);
/*
{
"id": "xxXxXxxxXxxx",
"name": "test.zip",
"size": 156,
"created_at": 1572458477,
"transcode_status": "not_applicable",
"folder_id": "XxXXXxxxxxx",
"ip": "1.1.1.1",
"acodec": "",
"vcodec": "",
"mime_type": "application/zip",
"opensubtitles_hash": "",
"resx": "",
"resy": "",
"duration": "",
"virus_scan": "ok",
"type": "file",
"link": "https://down.host.example.com/dl/abcdefg/test.zip",
"stream_link": null
}
*/
if("link" in result && result.link) {
cb(result.link, url);
} else {
window.setTimeout(function () {
self._getSingleLink(url, fileId, cb)
}, self.updateDownloadProgressInterval)
}
}
});
};
})(),
'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.updateStatusURL = 'https://www.nopremium.pl/files';
this.updateStatusURLpattern =/https?:\/\/www\.nopremium\.pl\/files\/?/;
this.updateDownloadProgressInterval = 5000;
var mapHosterName = function(name) {return name.replace("-","")};
this.status = {};
this.init = async function() {
self.status = JSON.parse(await GM.getValue(self.key+"_status","{}"));
self.lastUpdate = new Date(await GM.getValue(self.key+"_status_time",0));
};
this.settings = {};
this.loadSettings = async function(silent) {
// Load settings, use first value as default
var savedsettings = JSON.parse(await GM.getValue(self.key+"_settings","{}"));
for(var key in self.config) {
if(key.endsWith("desc") || key.endsWith("range") || key.endsWith("quest") || key.endsWith("prefix") || key.endsWith("suffix")) {
continue;
}
if(key in savedsettings) { // Saved
if(self.config[key] == 'int') { // Int
self.settings[key] = parseInt(savedsettings[key],10);
} else if(self.config[key] == 'string') { // String
self.settings[key] = savedsettings[key].toString();
} else if(config[key] == 'bool') { // Bool
self.settings[key] = savedsettings[key]=="true"||savedsettings[key]===true;
} else if(Array.isArray(savedsettings[key])) { // Nested array
self.settings[key] = [];
for(var i = 0; i < savedsettings[key].length; i++) {
self.settings[key].push(savedsettings[key][i]);
}
} else { // Array
self.settings[key] = savedsettings[key];
}
} else { // Default
if(self.config[key] == 'int') { // Int
self.settings[key] = self.config[key+"_range"][1];
} else if(self.config[key] == 'string') { // String
self.settings[key] = ''; // String defaults to empty string
} else if(config[key] == 'bool') { // Bool
self.settings[key] = true;
} else if(Array.isArray(self.config[key][0])) { // Nested array defaults to first value for each array
self.settings[key] = [];
for(var i = 0; i < self.config[key].length; i++) {
self.settings[key].push(self.config[key][i][0]);
}
} else {
self.settings[key] = self.config[key][0]; // Array defaults to first value
}
}
}
};
this.updateStatus = async function() { // Update list of online hosters
if(document.location.href.match(self.updateStatusURL)) {
// Read and save current status of all hosters
self.status = {};
$("#servers a[title]").each(function() {
var name = mapHosterName(this.title);
self.status[name] = true;
});
await GM.setValue(self.key+"_status",JSON.stringify(self.status));
await GM.setValue(self.key+"_status_time",""+(new Date()));
console.log(s_myname+": "+self.name+": Hosters ("+Object.keys(self.status).length+") updated");
} else {
alert(s_myname+"\n\nError: wrong update URL");
}
};
this.isOnline = function(hostername) {
return hostername in self.status && self.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" // FIREFOX57
},
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,async function(hashes,size) {
if(settings.mode == 'transfer') {
await 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] == 'string') { // String
$('').addClass("form_"+formid).data("key",key).data("parse","string").val(s[key]).appendTo($p);
} 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"]);
}
}
}
async 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(!(key in newsettings[namespace]) || !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;
}
});
await GM.setValue("setup",true);
await GM.setValue("currentdebrid",currentdebrid);
await GM.setValue("settings",JSON.stringify(newsettings.general));
for(var key in multi) {
await GM.setValue(key+"_settings",JSON.stringify(newsettings[key]));
}
alert(s_myname+"\n\nSettings were successfully saved!");
document.location.reload();
}
async function aboutMe() {
var popup = popUp("multiochhelper_about",null,null,true);
var $popup = popup.node;
var $frame = $('