Input to Output

Copies 'copy' button to output

  1. // ==UserScript==
  2. // @name Input to Output
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.1
  5. // @description Copies 'copy' button to output
  6. // @author SuperJava
  7. // @match http://codeforces.com/*/*/*/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. document.querySelector('body').addEventListener('click', function(event) {
  12. if (event.target.className.toLowerCase() === 'jgrowl-closer default') {
  13. document.getElementById('jGrowl').outerHTML = '<div id="jGrowl" class="bottom-right jGrowl"><div class="jGrowl-notification"></div></div>';
  14. }
  15. });
  16.  
  17. $("body").bind("DOMNodeInserted",function(event){
  18. if(event.target.className.toLowerCase() === 'jgrowl-notification default'){
  19. setTimeout(function() {
  20. $(event.target).fadeOut(500, function(){$(this).remove();});
  21. }, 5000);
  22. }
  23. });
  24.  
  25. $("body").bind("DOMNodeInserted",function(event){
  26. if(event.target.className.toLowerCase() === 'jgrowl-closer default'){
  27. setTimeout(function() {
  28. $(event.target).fadeOut(500, function(){$(this).remove();});
  29. }, 5500);
  30. }
  31. });
  32.  
  33. var nof = document.createElement('div');
  34. document.getElementsByTagName('body')[0].appendChild(nof);
  35. nof.outerHTML = '<div id="jGrowl" class="bottom-right jGrowl"><div class="jGrowl-notification"></div></div>';
  36.  
  37. function copyToClipboard(text) {
  38. if (window.clipboardData && window.clipboardData.setData) {
  39. return clipboardData.setData("Text", text);
  40. } else if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
  41. var textarea = document.createElement("textarea");
  42. textarea.textContent = text;
  43. textarea.style.position = "fixed";
  44. document.body.appendChild(textarea);
  45. textarea.select();
  46. try {
  47. return document.execCommand("copy");
  48. } catch (ex) {
  49. console.warn("Copy to clipboard failed.", ex);
  50. return false;
  51. } finally {
  52. document.body.removeChild(textarea);
  53. }
  54. }
  55. }
  56.  
  57. var x = document.getElementsByClassName('output');
  58.  
  59. var len = x.length;
  60. for (var i = 0; i < len; ++i) {
  61. x[i].getElementsByClassName('title')[0].outerHTML = '<div class="title"> Output<div title="Copy" class="input-copier">Copy</div></div>';
  62. }
  63.  
  64. x = document.getElementsByClassName('output');
  65.  
  66. len = x.length;
  67. for (var i = 0; i < len; ++i) {
  68. x[i].getElementsByClassName('title')[0].getElementsByClassName('input-copier')[0].onclick = function(event){miracle(event);};
  69. }
  70.  
  71.  
  72.  
  73. function miracle(event) {
  74. var eea = event.currentTarget;
  75. var testx = eea.parentElement.parentElement.getElementsByTagName("PRE")[0];
  76. var nsq = testx.innerHTML.replace(/<br>/gi,"\n");
  77. copyToClipboard(nsq);
  78. var not = '<div class="jGrowl-notification default" style="display: block;"><div class="close notif">×</div><div class="header"></div><div class="message">The example has been copied into the clipboard</div></div>';
  79. // document.getElementById('jGrowl').appendChild(not);
  80. var er = document.getElementsByClassName('jGrowl-closer');
  81. if(er.length===0)
  82. $(not).hide().appendTo("#jGrowl").fadeIn(500);
  83. else{
  84. $(not).hide().insertBefore('.jGrowl-closer.default').fadeIn(500);
  85. }
  86. //$('.jGrowl-notification.default').mouseleave(function(){$(this).fadeOut(500, function(){$(this).remove();});});
  87. $('.close.notif').click(function(){
  88. $(this).parent().fadeOut(500, function(){$(this).remove();});
  89. });
  90. }