Compare commits

..

No commits in common. "33028cd7eba6f00c323351956f081755415a1ec1" and "1080863bdffa10daba7937524acfbfc0a1f662ee" have entirely different histories.

6 changed files with 67 additions and 71 deletions

View file

@ -11,14 +11,14 @@
AdiUserscriptLib.addButton('Wget Cmd', function () { AdiUserscriptLib.addButton('Wget Cmd', function () {
var vars = {} var vars = {}
var commandline = 'wget -cO "{name}" --referer="{ref}" {url}\n' var commandline = 'wget -cO "{name}" --referer="{ref}" {url}'
var commands = '' var commands = ''
vars.name = $('b.nhsTrackTitle').text() vars.name = $('b.nhsTrackTitle').text()
vars.url = $('button.nhsGrayBtnSmDownload').attr('href') vars.url = $('button.nhsGrayBtnSmDownload').attr('href')
vars.ref = window.location.href vars.ref = window.location.href
commands += AdiUserscriptLib.interpolate(commandline, vars) commands += AdiUserscriptLib.interpolate(commandline, vars) + '\n'
var w = window.open(); var w = window.open();
w.document.write('<pre>' + commands + '</pre>') w.document.write('<pre>' + commands + '</pre>')

116
lib.js
View file

@ -1,72 +1,68 @@
// Nice overview: AdiUserscriptLib = {}
// http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html
if (typeof AdiUserscriptLib != 'object') AdiUserscriptLib.interpolate = function (s, a) {
(function(public){ // Oh, well... http://stackoverflow.com/a/16804092
for (x in a) {
public.interpolate = function (s, a) { var token = '{' + x + '}'
// Oh, well... http://stackoverflow.com/a/16804092 var i = 0
for (x in a) { while ( (i = s.indexOf(token, i)) >= 0) s = s.replace(token, a[x])
var token = '{' + x + '}'
var i = 0
while ( (i = s.indexOf(token, i)) >= 0) s = s.replace(token, a[x])
}
return s
} }
return s
}
public.pad = function (x, len, char) { AdiUserscriptLib.pad = function (x, len, char) {
x = x.toString() x = x.toString()
while (x.length < len) x = char + x while (x.length < len) x = char + x
return x return x
}
AdiUserscriptLib.bind3 = function (fn, arg1, arg2, arg3) {
return function (a4,a5,a6) {
return fn(arg1,arg2,arg3,a4,a5,a6)
} }
}
public.bind3 = function (fn, arg1, arg2, arg3) { AdiUserscriptLib.binder3 = function (fn, callback) {
return function (a4,a5,a6) { return function (arg1, arg2, arg3) {
return fn(arg1,arg2,arg3,a4,a5,a6) 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.binder3 = function (fn, callback) { var fn = function (name, fn) {
return function (arg1, arg2, arg3) { var el = $('<button>' + name + '</button>')
var bound = public.bind3(fn, arg1, arg2, arg3) .css('position', 'fixed')
if (callback) callback(bound) .css('top', top)
} .css('left', left)
.css('z-index', 1000)
el.click(makeDoAndRemoveFn(fn, el))
$(document.body).append(el)
top = top + space
} }
public.doWhenReady = function (fn) { return AdiUserscriptLib.makeDoWhenReadyFn(fn)
$(document).ready(fn)
}
public.makeDoWhenReadyFn = function (fn) { }())
return public.binder3(fn, public.doWhenReady)
}
public.addButton = (function () { // EOF AdiUserscriptLib
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 = $('<button>' + name + '</button>')
.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 = {}))

View file

@ -9,15 +9,15 @@
// @grant none // @grant none
// ==/UserScript== // ==/UserScript==
AdiUserscriptLib.addButton('DL Cmds', function () { AdiUserscriptLib.addButton('Track Links', function () {
var vars = {} var vars = {}
var commandline = 'youtube-dl https://www.mixcloud.com{url}\n' var commandline = 'youtube-dl https://www.mixcloud.com{url}'
var commands = '' var commands = ''
$('.play-button').each(function () { $('.play-button').each(function () {
vars.url = $(this).attr('m-url') vars.url = $(this).attr('m-url')
if (!vars.url) break if (!vars.url) break
commands += AdiUserscriptLib.interpolate(commandline, vars) commands += AdiUserscriptLib.interpolate(commandline, vars) + '\n'
}) })
var w = window.open(); var w = window.open();

View file

@ -11,14 +11,14 @@
AdiUserscriptLib.addButton('Wget Cmds', function () { AdiUserscriptLib.addButton('Wget Cmds', function () {
var vars = {} var vars = {}
var commandline = 'wget -cO "{name}.mp3" {url}\n' var commandline = 'wget -cO "{name}.mp3" {url}'
var commands = '' var commands = ''
$('a.podcast-title').each(function () { $('a.podcast-title').each(function () {
divlinks = $(this).nextUntil('div.links').next() divlinks = $(this).nextUntil('div.links').next()
vars.url = divlinks.find('a:contains("Download")').attr('href') vars.url = divlinks.find('a:contains("Download")').attr('href')
vars.name = $(this).text() vars.name = $(this).text()
commands += AdiUserscriptLib.interpolate(commandline, vars) commands += AdiUserscriptLib.interpolate(commandline, vars) + '\n'
}) })
var w = window.open(); var w = window.open();

View file

@ -11,10 +11,10 @@
AdiUserscriptLib.addButton('Search Torrentz', function () { AdiUserscriptLib.addButton('Search Torrentz', function () {
var regex = new RegExp('/cat/([^/]+)/Season-([0-9]+)/Episode-([0-9]+)') var regex = new RegExp('/cat/([^/]+)/Season-([0-9]+)/Episode-([0-9]+)')
var url = 'https://torrentz.eu/search?q={name}+S{season}E{episode}' var url = 'http://torrentz.eu/search?f={name}+S{season}E{episode}'
var X = AdiUserscriptLib
$('a').each(function () { $('a').each(function () {
var X = AdiUserscriptLib
var matches = regex.exec(this.href) var matches = regex.exec(this.href)
if (matches) { if (matches) {
var replacements = { var replacements = {

View file

@ -11,7 +11,7 @@
AdiUserscriptLib.addButton('Wget Cmd', function () { AdiUserscriptLib.addButton('Wget Cmd', function () {
var vars = {} var vars = {}
var commandline = 'wget -cO "{name}" --header="Cookie: JSESSIONID={sessioncookie}" {url}\ntouch -d "{date}" "{name}"\n' var commandline = 'wget -cO "{name}" --header="Cookie: JSESSIONID={sessioncookie}" {url}\ntouch -d "{date}" "{name}"'
var commands = '' var commands = ''
vars.name = $('font:contains("Name: ") + font').text() 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})(.+)/) var datematch = vars.date.match(/^(\d{2})-(\d{2})-(\d{4})(.+)/)
vars.date = AdiUserscriptLib.interpolate('{3}-{2}-{1}{4}', datematch) vars.date = AdiUserscriptLib.interpolate('{3}-{2}-{1}{4}', datematch)
commands += AdiUserscriptLib.interpolate(commandline, vars) commands += AdiUserscriptLib.interpolate(commandline, vars) + '\n'
var w = window.open(); var w = window.open();
w.document.write('<pre>' + commands + '</pre>') w.document.write('<pre>' + commands + '</pre>')