巴哈SauceNAO圖搜按鈕

在巴哈姆特的文章加入SauceNAO圖搜按鈕

  1. // ==UserScript==
  2. // @name 巴哈SauceNAO圖搜按鈕
  3. // @namespace https://home.gamer.com.tw/Mogeko12345
  4. // @version 1.0.3
  5. // @description 在巴哈姆特的文章加入SauceNAO圖搜按鈕
  6. // @author mogeko12345
  7. // @match https://forum.gamer.com.tw/C.php*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function(){
  12. function hasClass(parent, className){
  13. return parent.getElementsByClassName(className).length === 0 ? false : true;
  14. }
  15. function search(){
  16. var article = document.getElementsByClassName("c-article FM-P2")[this.value];
  17. var img = hasClass(article, "photoswipe-image") ? article.getElementsByClassName("photoswipe-image") : article.getElementsByClassName("loadpic photoswipe-image-shrink");
  18. for(var ii = 0; ii < img.length; ii++){
  19. window.open("http://saucenao.com/search.php?db=999&url=" + img[ii].href, "_blank");
  20. }
  21. }
  22. var header = document.getElementsByClassName("c-post__header__tools");
  23. for(var i = 0; i < header.length; i++){
  24. var article = document.getElementsByClassName("c-article FM-P2")[i];
  25. if(hasClass(article, "photoswipe-image") || hasClass(article, "loadpic photoswipe-image-shrink")){
  26. var button = document.createElement("button");
  27. var inner = document.createElement("i");
  28. inner.className = "icon-font";
  29. inner.textContent = "搜";
  30. button.className = "ef-btn";
  31. button.value = i;
  32. button.addEventListener("click", search);
  33. button.appendChild(inner);
  34. header[i].appendChild(button);
  35. }
  36. }
  37. })();