Last active
October 21, 2018 09:42
-
-
Save velnias75/2eb5a3625640ada0007d3d2c0de09eb5 to your computer and use it in GitHub Desktop.
Userscript um Filme von omdb in der Datenbank https://rangun.de/index.php zu suchen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name OMDB - Suche in der DB | |
// @version 0.15 | |
// @description Userscript um Filme von omdb in der Datenbank https://rangun.de/index.php zu suchen | |
// @author Heiko Schäfer | |
// @homepage https://gist.github.com/velnias75/2eb5a3625640ada0007d3d2c0de09eb5 | |
// @updateURL https://gist.github.com/velnias75/2eb5a3625640ada0007d3d2c0de09eb5/raw/omdb.user.js | |
// @downloadURL https://gist.github.com/velnias75/2eb5a3625640ada0007d3d2c0de09eb5/raw/omdb.user.js | |
// @namespace https://rangun.de/db/ | |
// @match http://www.omdb.org/person/*/filmography | |
// @match http://www.omdb.org/movie/* | |
// @match http://www.omdb.org/user/* | |
// @match https://www.omdb.org/person/*/filmography | |
// @match https://www.omdb.org/movie/* | |
// @match https://www.omdb.org/user/* | |
// @require https://cdn.jsdelivr.net/g/jquery | |
// @run-at document-end | |
// @connect * | |
// @grant GM_xmlhttpRequest | |
// @grant GM_getValue | |
// @grant GM_setValue | |
// ==/UserScript== | |
function escapeRegExp(string) { | |
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string | |
} | |
var pathname = window.location.pathname; | |
if(pathname.match(/\/person\/[^\/]+\/filmography/)) { | |
$("table#filmography tbody > tr").each(function(i) { | |
var temel = $(this).find("td a"); | |
var title = temel.text().replace(/ - /g, " – "); | |
if(title.length) { | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: GM_getValue('webvirus_url', 'https://rangun.de/db') + "/title-json.php?filter_ltitle=" + | |
encodeURIComponent("/^" + escapeRegExp(title) + "$/"), | |
anonymous: true, | |
timeout: 0, | |
onload: function(response) { | |
if(response.status == 200) { | |
var json = eval(response.responseText); | |
if(typeof json[0] != 'undefined' && json.length == 1) { | |
$(document).ready(function () { | |
temel.text('⚠ ' + title + ' ⚠'); | |
}); | |
} | |
} | |
} | |
}); | |
} | |
}); | |
} | |
if(pathname.substring(1, 5) == 'movi') { | |
var title = $("#headline > h2:nth-child(2)").text().replace(/ - /g, " – "); | |
var o_title = $("#headline > h3:nth-child(3)").text().replace(/ - /g, " – "); | |
var aliases = o_title.length > 0 ? ("(" + escapeRegExp(o_title.trim()).replace(/ - /g, " – ") + ")|") : ""; | |
$("#overview-aliases.content-box ul li").each(function(i) { | |
aliases += "(" + escapeRegExp($(this).text().trim()).replace(/ - /g, " – ") + ")|"; | |
}); | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: GM_getValue('webvirus_url', 'https://rangun.de/db') + "/title-json.php?id=1&filter_ltitle=" + | |
encodeURIComponent("/^" + aliases + "(" + escapeRegExp(title) + ")$/"), | |
anonymous: true, | |
timeout: 0, | |
onload: function(response) { | |
if(response.status == 200) { | |
var json = eval(response.responseText); | |
if(typeof json[0] != 'undefined' && json.length == 1) { | |
$("div#external-links.wikilist ul"). | |
append('<li><a target="webvirus" href="' + GM_getValue('webvirus_url', 'https://rangun.de/db') + '/index.php?filter_ltitle=' + | |
"%23" + json[0].id + '">Zeige in der DB</a></li>'); | |
$(document).ready(function () { | |
var th = $("#headline > h2:nth-child(2)"); console.log(encodeURIComponent(document.location.toString())); | |
th.html('✋ #' + json[0].id + " - " + $("#headline > h2:nth-child(2)").text() + ' ✋'); | |
if(GM_getValue('webvirus_ombd_id_update', false)) { | |
th.append('<a title="Übernehme omdb-ID in DB" href="' + GM_getValue('webvirus_url', 'https://rangun.de/db') + '/omdb.php?mid=' + | |
json[0].id + '&oid=' + /^\/movie\/([0-9]+)\-.*$/.exec(document.location.pathname)[1] + | |
'&url=' + encodeURIComponent(document.location.toString()) + '">☑</a>'); | |
} | |
}); | |
} | |
} | |
} | |
}); | |
} | |
if(pathname.substring(1, 5) == 'user') { | |
$('div#overview-details').append('<div class="headline-box"><h3>DB-Link einstellen</h3></div><div class="content-box"><input id="webvirus-url" type="text" value="' + | |
GM_getValue('webvirus_url', 'https://rangun.de/db') + '" /></div>'); | |
$('#webvirus-url').on('input', function() { | |
GM_setValue('webvirus_url', $(this).val()); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment