Animesong

いわゆるコピペを可能とするアレ

  1. // ==UserScript==
  2. // @name Animesong
  3. // @namespace https://twitter.com/akameco
  4. // @description いわゆるコピペを可能とするアレ
  5. // @include http://www.jtw.zaq.ne.jp/animesong/*
  6. // @version 1
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. // enable focus text
  11. function enableCopyText() {
  12. // set attributes for body
  13. document.body.setAttribute("oncontextmenu","return true");
  14. document.body.setAttribute("onselectstart","return true");
  15. }
  16.  
  17. // select all textarea
  18. function selectText(c) {
  19. let element= document.querySelector(c);
  20. // create range
  21. let rng = document.createRange();
  22. rng.selectNodeContents(element);
  23. // add range for the selected regions
  24. window.getSelection().addRange(rng);
  25. }
  26.  
  27. // create new button
  28. function createCopyButton() {
  29. let button = document.createElement("button");
  30. // set text
  31. button.innerHTML = "選択";
  32. button.style.margin = "0px 0px 10px 0px";
  33. button.style.borderTop = "1px solid #ccc";
  34. button.style.borderRight = "1px solid #999";
  35. button.style.borderBottom = "1px solid #999";
  36. button.style.borderLeft = "1px solid #ccc";
  37. button.style.padding = "3px 12px";
  38. button.style.cursor = "pointer";
  39. button.style.color = "#666";
  40.  
  41. button.addEventListener("click",function(){selectText(".b")},false);
  42. let frame = document.querySelector("tbody");
  43. frame.appendChild(button);
  44. // swap elements
  45. button.parentNode.insertBefore(button,button.parentNode.firstChild);
  46.  
  47. }
  48.  
  49. window.onload = function () {
  50. setTimeout(function() {
  51. enableCopyText();
  52. createCopyButton();
  53. }, 10);
  54. }