diff --git a/hulkshare.js b/hulkshare.js index 6d682c0..e82157c 100644 --- a/hulkshare.js +++ b/hulkshare.js @@ -11,14 +11,14 @@ AdiUserscriptLib.addButton('Wget Cmd', function () { var vars = {} - var commandline = 'wget -cO "{name}" --referer="{ref}" {url}' + var commandline = 'wget -cO "{name}" --referer="{ref}" {url}\n' var commands = '' vars.name = $('b.nhsTrackTitle').text() vars.url = $('button.nhsGrayBtnSmDownload').attr('href') vars.ref = window.location.href - commands += AdiUserscriptLib.interpolate(commandline, vars) + '\n' + commands += AdiUserscriptLib.interpolate(commandline, vars) var w = window.open(); w.document.write('
' + commands + '
') diff --git a/lib.js b/lib.js index 308ab4b..34ad5b7 100644 --- a/lib.js +++ b/lib.js @@ -1,68 +1,72 @@ -AdiUserscriptLib = {} +// Nice overview: +// http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html -AdiUserscriptLib.interpolate = function (s, a) { - // Oh, well... http://stackoverflow.com/a/16804092 - for (x in a) { - var token = '{' + x + '}' - var i = 0 - while ( (i = s.indexOf(token, i)) >= 0) s = s.replace(token, a[x]) +if (typeof AdiUserscriptLib != 'object') +(function(public){ + + public.interpolate = function (s, a) { + // Oh, well... http://stackoverflow.com/a/16804092 + for (x in a) { + var token = '{' + x + '}' + var i = 0 + while ( (i = s.indexOf(token, i)) >= 0) s = s.replace(token, a[x]) + } + return s } - return s -} -AdiUserscriptLib.pad = function (x, len, char) { - x = x.toString() - while (x.length < len) x = char + x - return x -} - -AdiUserscriptLib.bind3 = function (fn, arg1, arg2, arg3) { - return function (a4,a5,a6) { - return fn(arg1,arg2,arg3,a4,a5,a6) + public.pad = function (x, len, char) { + x = x.toString() + while (x.length < len) x = char + x + return x } -} -AdiUserscriptLib.binder3 = function (fn, callback) { - return function (arg1, arg2, arg3) { - var bound = AdiUserscriptLib.bind3(fn, arg1, arg2, arg3) - if (callback) callback(bound) - } -} - -AdiUserscriptLib.doWhenReady = function (fn) { - $(document).ready(fn) -} - -AdiUserscriptLib.makeDoWhenReadyFn = function (fn) { - return AdiUserscriptLib.binder3(fn, AdiUserscriptLib.doWhenReady) -} - -AdiUserscriptLib.addButton = (function () { - - var left = 12 - var top = 64 - var space = 32 - - var makeDoAndRemoveFn = function (fn, el) { - return function () { - fn() - el.text(el.text() + ' ✓') + public.bind3 = function (fn, arg1, arg2, arg3) { + return function (a4,a5,a6) { + return fn(arg1,arg2,arg3,a4,a5,a6) } } - var fn = function (name, fn) { - var el = $('') - .css('position', 'fixed') - .css('top', top) - .css('left', left) - .css('z-index', 1000) - el.click(makeDoAndRemoveFn(fn, el)) - $(document.body).append(el) - top = top + space + public.binder3 = function (fn, callback) { + return function (arg1, arg2, arg3) { + var bound = public.bind3(fn, arg1, arg2, arg3) + if (callback) callback(bound) + } } - return AdiUserscriptLib.makeDoWhenReadyFn(fn) + public.doWhenReady = function (fn) { + $(document).ready(fn) + } -}()) + public.makeDoWhenReadyFn = function (fn) { + return public.binder3(fn, public.doWhenReady) + } -// EOF AdiUserscriptLib + public.addButton = (function () { + + var left = 12 + var top = 64 + var space = 32 + + var makeDoAndRemoveFn = function (fn, el) { + return function () { + fn() + el.text(el.text() + ' ✓') + } + } + + var fn = function (name, fn) { + var el = $('') + .css('position', 'fixed') + .css('top', top) + .css('left', left) + .css('z-index', 1000) + el.click(makeDoAndRemoveFn(fn, el)) + $(document.body).append(el) + top = top + space + } + + return public.makeDoWhenReadyFn(fn) + + }()) + +}(AdiUserscriptLib = {})) diff --git a/mixcloud.js b/mixcloud.js index e69e2be..0fd0c45 100644 --- a/mixcloud.js +++ b/mixcloud.js @@ -9,15 +9,15 @@ // @grant none // ==/UserScript== -AdiUserscriptLib.addButton('Track Links', function () { +AdiUserscriptLib.addButton('DL Cmds', function () { var vars = {} - var commandline = 'youtube-dl https://www.mixcloud.com{url}' + var commandline = 'youtube-dl https://www.mixcloud.com{url}\n' var commands = '' $('.play-button').each(function () { vars.url = $(this).attr('m-url') if (!vars.url) break - commands += AdiUserscriptLib.interpolate(commandline, vars) + '\n' + commands += AdiUserscriptLib.interpolate(commandline, vars) }) var w = window.open(); diff --git a/podomatic.js b/podomatic.js index 21ba59d..d1f4cc9 100644 --- a/podomatic.js +++ b/podomatic.js @@ -11,14 +11,14 @@ AdiUserscriptLib.addButton('Wget Cmds', function () { var vars = {} - var commandline = 'wget -cO "{name}.mp3" {url}' + var commandline = 'wget -cO "{name}.mp3" {url}\n' var commands = '' $('a.podcast-title').each(function () { divlinks = $(this).nextUntil('div.links').next() vars.url = divlinks.find('a:contains("Download")').attr('href') vars.name = $(this).text() - commands += AdiUserscriptLib.interpolate(commandline, vars) + '\n' + commands += AdiUserscriptLib.interpolate(commandline, vars) }) var w = window.open(); diff --git a/tvcaltorrentz.js b/tvcaltorrentz.js index f496188..c7a56a1 100644 --- a/tvcaltorrentz.js +++ b/tvcaltorrentz.js @@ -11,10 +11,10 @@ AdiUserscriptLib.addButton('Search Torrentz', function () { var regex = new RegExp('/cat/([^/]+)/Season-([0-9]+)/Episode-([0-9]+)') - var url = 'http://torrentz.eu/search?f={name}+S{season}E{episode}' + var url = 'https://torrentz.eu/search?q={name}+S{season}E{episode}' + var X = AdiUserscriptLib $('a').each(function () { - var X = AdiUserscriptLib var matches = regex.exec(this.href) if (matches) { var replacements = { diff --git a/zippyshare.js b/zippyshare.js index 53dc233..05d917b 100644 --- a/zippyshare.js +++ b/zippyshare.js @@ -11,7 +11,7 @@ AdiUserscriptLib.addButton('Wget Cmd', function () { var vars = {} - var commandline = 'wget -cO "{name}" --header="Cookie: JSESSIONID={sessioncookie}" {url}\ntouch -d "{date}" "{name}"' + var commandline = 'wget -cO "{name}" --header="Cookie: JSESSIONID={sessioncookie}" {url}\ntouch -d "{date}" "{name}"\n' var commands = '' vars.name = $('font:contains("Name: ") + font').text() @@ -23,7 +23,7 @@ AdiUserscriptLib.addButton('Wget Cmd', function () { var datematch = vars.date.match(/^(\d{2})-(\d{2})-(\d{4})(.+)/) vars.date = AdiUserscriptLib.interpolate('{3}-{2}-{1}{4}', datematch) - commands += AdiUserscriptLib.interpolate(commandline, vars) + '\n' + commands += AdiUserscriptLib.interpolate(commandline, vars) var w = window.open(); w.document.write('
' + commands + '
')