Greasy Fork is available in English.

巴哈姆特哈拉開圖器 fixed

直接顯示巴哈姆特哈啦區文章的圖片和影片。跳過站外連結警告。

  1. // ==UserScript==
  2. // @name 巴哈姆特哈拉開圖器 fixed
  3. // @description 直接顯示巴哈姆特哈啦區文章的圖片和影片。跳過站外連結警告。
  4. // @namespace eight04.blogspot.com
  5. // @include http://forum.gamer.com.tw/*
  6. // @include https://forum.gamer.com.tw/*
  7. // @version 1.3.0
  8. // @author akiratw
  9. // @contributor eight04 <eight04@gmail.com> (https://github.com/eight04)
  10. // @homepage https://github.com/eight04/baha-embed-images
  11. // @supportURL https://github.com/eight04/baha-embed-images/issues
  12. // @license MIT
  13. // @compatible firefox
  14. // @compatible chrome
  15. // @grant none
  16. // ==/UserScript==
  17.  
  18. /* globals getCookie */
  19.  
  20. if (getCookie("ckForumLegend") == "yes") {
  21. displayImage();
  22. displayYouTube();
  23. }
  24. redirectLinks();
  25.  
  26. function redirectLinks() {
  27. var links = document.querySelectorAll('a'),
  28. regex = /.*redir\.php\?url=(.+)/i;
  29.  
  30. for (var i = links.length - 1; i >= 0; i--) {
  31. var link = links[i],
  32. url = link.getAttribute('href');
  33.  
  34. if (regex.test(url)) {
  35. link.setAttribute(
  36. 'href',
  37. decodeURIComponent(url.replace(regex, '$1'))
  38. );
  39. }
  40. if (link.onclick && link.matches("#BH-master article a")) {
  41. link.onclick = null;
  42. }
  43. }
  44. }
  45.  
  46. function displayYouTube() {
  47. var links = document.querySelectorAll('a'),
  48. regex = /.*(?:youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#&?]*).*/i;
  49.  
  50. for (var i = links.length - 1; i >= 0; i--) {
  51. var link = links[i],
  52. url = link.getAttribute('href');
  53. if (!url) continue;
  54. var matches = url.match(regex);
  55.  
  56. if (matches) {
  57. url = '//www.youtube.com/embed/' + matches[1];
  58. var iframe = document.createElement('iframe');
  59. iframe.setAttribute('width', '560');
  60. iframe.setAttribute('height', '315');
  61. iframe.setAttribute('frameborder', '0');
  62. iframe.setAttribute('allowfullscreen', 'true');
  63. iframe.setAttribute('src', url);
  64. link.parentNode.replaceChild(iframe, link);
  65. }
  66. }
  67. }
  68.  
  69. function displayImage() {
  70. var links = document.querySelectorAll('a'),
  71. limit = 3;
  72. links = Array.from(links);
  73. while (limit--) {
  74. deque();
  75. }
  76. function deque() {
  77. var link = links.shift();
  78. if (!link) return;
  79. var src = link.id || link.href;
  80. if (!/(\.gif|\.jpg|\.jpeg|\.png|\.bmp)/i.test(src) || !/圖片|開圖/.test(link.textContent)) {
  81. return deque();
  82. }
  83. var img = new Image;
  84. img.src = src;
  85. img.addEventListener("load", handleLoad);
  86. img.addEventListener("error", handleLoad);
  87. link.innerHTML = "";
  88. link.onclick = null;
  89. link.target = "_blank";
  90. link.appendChild(img);
  91. link.classList.remove("image-load");
  92. }
  93. function handleLoad(e) {
  94. e.target.removeEventListener("load", handleLoad);
  95. e.target.removeEventListener("error", handleLoad);
  96. return deque();
  97. }
  98. }