[niconico video] Adds a botton that add mylist to mylist page

Adds a button that add mylist to mylist page

当前为 2017-02-17 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name [niconico video] Adds a botton that add mylist to mylist page
  3. // @name:ja [ニコニコ動画] マイリストページからマイリストするボタンを追加
  4. // @description Adds a button that add mylist to mylist page
  5. // @description:ja マイリストページからマイリストするボタンを追加
  6. // @namespace masshiro.wpblog.jp
  7. // @version 0.1
  8. // @author masshiro
  9. // @match http://www.nicovideo.jp/mylist/*
  10. // @grant none
  11. // ==/UserScript==
  12. /*
  13. var addbottons = function()
  14. {
  15. 'use strict';
  16.  
  17. var span = document.createElement('span');
  18. span.className = "value";
  19. span.style="color:#F00;text-decoration:underline;cursor:pointer";
  20. span.innerHTML="追加";
  21.  
  22. var a = document.createElement('a');
  23. a.appendChild(span);
  24.  
  25. a.addEventListener('click',function () {
  26. window.open("http://www.nicovideo.jp/mylist_add/video/" + encodeURIComponent(document.querySelectorAll(".SYS_box_item a")[0].getAttribute("href").replace("watch/","")), "nicomylistadd", "width=500, height=400, menubar=no, scrollbars=no");
  27. },false);
  28.  
  29. Array.prototype.forEach.call(document.querySelectorAll(".SYS_box_item_buttons p"), function(item,i) {
  30. var as = a.cloneNode(true);
  31. as.addEventListener('click',function () {
  32. window.open("http://www.nicovideo.jp/mylist_add/video/" + encodeURIComponent(document.querySelectorAll(".SYS_box_item a")[i].getAttribute("href").replace("watch/","")), "nicomylistadd", "width=500, height=400, menubar=no, scrollbars=no");
  33. },false);
  34. item.appendChild(as);
  35. });
  36. }
  37. */
  38. (function () {
  39. 'use strict';
  40.  
  41. var addButtons = function () {
  42. var span = document.createElement('span');
  43. span.style="color:#F00;text-decoration:underline;cursor:pointer";
  44. span.innerHTML="追加";
  45.  
  46. var a = document.createElement('a');
  47. a.className = "addmylist";
  48. a.appendChild(span);
  49.  
  50. a.addEventListener('click',function () {
  51. window.open("http://www.nicovideo.jp/mylist_add/video/" + encodeURIComponent(document.querySelectorAll(".SYS_box_item")[0].querySelectorAll("a")[0].getAttribute("href").replace("watch/","")), "nicomylistadd", "width=500, height=400, menubar=no, scrollbars=no");
  52. },false);
  53.  
  54. Array.prototype.forEach.call(document.querySelectorAll(".SYS_box_item_buttons p"), function(item,i) {
  55. if(typeof item.querySelectorAll("a.addmylist")[0] === "undefined"){
  56. var as = a.cloneNode(true);
  57. as.addEventListener('click',function () {
  58. window.open("http://www.nicovideo.jp/mylist_add/video/" + encodeURIComponent(document.querySelectorAll(".SYS_box_item")[i].querySelectorAll("a")[0].getAttribute("href").replace("watch/","")), "nicomylistadd", "width=500, height=400, menubar=no, scrollbars=no");
  59. },false);
  60. item.appendChild(as);
  61. }
  62. });
  63. };
  64.  
  65. // DOM変更で再実行
  66. // コピー元 (ありがとうございました)
  67. // https://greasyfork.org/ja/scripts/15271-extract-images-for-twitter
  68. (function () {
  69. var DOMObserverTimer = false;
  70. var DOMObserverConfig = {
  71. attributes: true,
  72. childList: true,
  73. subtree: true
  74. };
  75. var DOMObserver = new MutationObserver(function () {
  76. if (DOMObserverTimer !== 'false') {
  77. clearTimeout(DOMObserverTimer);
  78. }
  79. DOMObserverTimer = setTimeout(function () {
  80. DOMObserver.disconnect();
  81. addButtons();
  82. DOMObserver.observe(document.body, DOMObserverConfig);
  83. }, 100);
  84. });
  85. DOMObserver.observe(document.body, DOMObserverConfig);
  86. }) ();
  87.  
  88. })();