Skip to content

Instantly share code, notes, and snippets.

@bitdust
Last active July 25, 2018 09:59
Show Gist options
  • Save bitdust/3b63ab636e5fd7be59d6a55ef9638351 to your computer and use it in GitHub Desktop.
Save bitdust/3b63ab636e5fd7be59d6a55ef9638351 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Douban2Piratebay
// @namespace https://github.com/bitdust/Douban2Piratebay
// @version 0.8
// @description Add direct link to piratebay from douban movie page.
// @author bitdust
// @match https://movie.douban.com/subject/*
// @grant none
// @updateURL https://gist.github.com/bitdust/3b63ab636e5fd7be59d6a55ef9638351/raw/Douban2Piratebay.user.js
// @downloadURL https://gist.github.com/bitdust/3b63ab636e5fd7be59d6a55ef9638351/raw/Douban2Piratebay.user.js
// ==/UserScript==
(function() {
'use strict';
// Your code here...
function insertAfter(newNode, referenceNode) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}
var links = document.querySelectorAll (
"#info > a"
);
var imdblink = null;
var imdbRe = new RegExp("tt[0-9]{4,}");
for (var i=0;i<links.length;i++) {
if(imdbRe.test(links[i].textContent)) {
imdblink = links[i];
break;
}
}
if (imdblink !== null) {
var imdbindex = imdblink.innerText;
var fragment = document.createDocumentFragment();
var br = document.createElement("br");
var parent = imdblink.parentElement;
var span = imdblink.previousElementSibling.cloneNode(false);
span.textContent = "海盗湾链接: ";
span.class = 'pl';
var a = imdblink.cloneNode(true);
a.href = 'https://thepiratebay.org/search/' + imdbindex;
fragment.appendChild(br);
fragment.appendChild(span);
fragment.appendChild(a);
insertAfter(fragment, imdblink);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment