-
-
Save eight04/c09090aab7e6077b1886 to your computer and use it in GitHub Desktop.
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 巴哈姆特哈拉開圖器 | |
// @namespace http://akr.tw/ | |
// @description 直接顯示巴哈姆特哈啦區文章的圖片和影片。跳過站外連結警告。 | |
// @author akiratw | |
// @version 1.1.1 | |
// @license MIT License | |
// @include http://forum.gamer.com.tw/* | |
// @grant none | |
// ==/UserScript== | |
var redirectLinks = function () { | |
var links = document.querySelectorAll('a'), | |
regex = /.*redir\.php\?url=(.+)/i; | |
for (var i = links.length - 1; i >= 0; i--) { | |
var link = links[i], | |
url = link.getAttribute('href'); | |
if (regex.test(url)) { | |
link.setAttribute( | |
'href', | |
decodeURIComponent(url.replace(regex, '$1')) | |
); | |
} | |
} | |
}(); | |
var displayImage = function () { | |
var links = document.querySelectorAll('.FM-cbox7 a'), | |
regex = /(\.gif|\.jpg|\.jpeg|\.png|\.bmp)/i; | |
for (var i = links.length - 1; i >= 0; i--) { | |
var link = links[i], | |
src = link.id || link.href; | |
if (regex.test(src) && link.textContent.indexOf("圖片") >= 0) { | |
link.innerHTML = '<img src="' + src + '" />'; | |
link.onclick = null; | |
link.target = "_blank"; | |
} | |
} | |
}(); | |
var displayYouTube = function () { | |
var links = document.querySelectorAll('a.T3_red'), | |
regex = /.*(?:youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/i; | |
for (var i = links.length - 1; i >= 0; i--) { | |
var link = links[i], | |
url = link.getAttribute('href'), | |
matches = url.match(regex); | |
if (matches) { | |
url = 'http://www.youtube.com/embed/' + matches[1]; | |
var iframe = document.createElement('iframe'); | |
iframe.setAttribute('width', '560'); | |
iframe.setAttribute('height', '315'); | |
iframe.setAttribute('frameborder', '0'); | |
iframe.setAttribute('allowfullscreen', 'true'); | |
iframe.setAttribute('src', url); | |
link.parentNode.replaceChild(iframe, link); | |
} | |
} | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment