Select-click-copy Enabler

Enables select, right-click, copy and drag on pages that disable them. WARNING: MAY BREAK PAGE FUNCTIONS.

  1. // ==UserScript==
  2. // @name Select-click-copy Enabler
  3. // @namespace http://userscripts.org/users/92143
  4. // @version 8.3
  5. // @description Enables select, right-click, copy and drag on pages that disable them. WARNING: MAY BREAK PAGE FUNCTIONS.
  6. // @include /^https?\:\/\//
  7. // @exclude /^https?\:\/\/([^\.]+\.)?facebook\.com/
  8. // @exclude /^https?\:\/\/([^\.]+\.)?google\.((?!\/cse\?).)+$/
  9. // @exclude /^https?\:\/\/([^\.]+\.)?wikipedia\.org/
  10. // @exclude /^https?\:\/\/([^\.]+\.)?wikimedia\.org/
  11. // @exclude /^https?\:\/\/([^\.]+\.)?youtube\.com/
  12. // @exclude /^https?\:\/\/([^\.]+\.)?yahoo\.co/
  13. // @exclude /^https?\:\/\/([^\.]+\.)?saucenao\.com/
  14. // @exclude /^https?\:\/\/myanimelist\.net\/editprofile\.php/
  15. // @exclude /^https?\:\/\/([^\.]+\.)?mitbbs\.com/
  16. // @exclude /^https?\:\/\/([^\.]+\.)?getchu\.com/
  17. // @exclude /^https?\:\/\/([^\.]+\.)?jsfiddle\.net/
  18. // @exclude /^https?\:\/\/([^\.]+\.)?fiddle\.jshell\.net/
  19. // @exclude /^https?\:\/\/([^\.]+\.)?jsbin\.com/
  20. // @exclude /^https?\:\/\/([^\.]+\.)?photojoiner\.net/
  21. // @exclude /^https?\:\/\/tieba\.baidu\.com/
  22. // @exclude /^https?\:\/\/w\.qq\.com/
  23. // @exclude /^https?\:\/\/web2\.qq\.com/
  24. // @exclude /^https?\:\/\/([^\.]+\.)?flagcounter\.com/
  25. // @exclude /^https?\:\/\/([^\.]+\.)?dm5\.com/
  26. // @exclude /^https?\:\/\/([^\.]+\.)?xinhuanet\.com/
  27. // @exclude /^https?\:\/\/([^\.]+\.)?newegg\.com/
  28. // @exclude /^https?\:\/\/([^\.]+\.)?doublemap\.com/
  29. // @exclude /^https?\:\/\/([^\.]+\.)*sina\.com\.cn/
  30. // @author zanetu
  31. // @license GPL version 2 or any later version; http://www.gnu.org/licenses/gpl-2.0.txt
  32. // @grant none
  33. // @run-at document-start
  34. // ==/UserScript==
  35.  
  36. var wasRun
  37. //increase this value to 1000 or greater for pages that need a long time to be loaded
  38. var BODY_DELAY = 100
  39.  
  40. function init() {
  41. wasRun = false
  42. }
  43.  
  44. function enableSelectClickCopy() {
  45. var events =
  46. ['copy', 'mouseup', 'mousedown', 'contextmenu', 'select', 'selectstart', 'dragstart']
  47. var topElements = [window, document]
  48. function disableAll(event) {
  49. if (event.stopImmediatePropagation) {
  50. event.stopImmediatePropagation()
  51. }
  52. else if (event.stopPropagation) {
  53. event.stopPropagation()
  54. }
  55. }
  56. for (var i = 0; i < events.length; i++) {
  57. var event = 'on' + events[i]
  58. for (var j = 0; j < topElements.length; j++) {
  59. topElements[j][event] = null
  60. }
  61. document.addEventListener(events[i], disableAll, true)
  62. }
  63. }
  64.  
  65. function loadedHandler() {
  66. if (wasRun) {
  67. return
  68. }
  69. wasRun = true
  70. document.removeEventListener('beforescriptexecute', loadedHandler, true)
  71. document.removeEventListener('beforeload', loadedHandler, true)
  72. document.removeEventListener('DOMContentLoaded', loadedHandler, true)
  73. appendScript(document)
  74. }
  75.  
  76. function loadedCssIframeHandler() {
  77. setTimeout(function() {
  78. appendCssEnabler(document.body)
  79. //handle iframes
  80. var oldBody, newBody
  81. for (var i = 0; i < frames.length; i++) {
  82. var iDocument
  83. try {
  84. iDocument = frames[i].document
  85. }
  86. //cross domain access, protocol mismatch, etc
  87. catch(securityError) {
  88. continue
  89. }
  90. if(iDocument) {
  91. oldBody = iDocument.body
  92. newBody = oldBody.cloneNode(true)
  93. prependScriptTo(newBody)
  94. appendCssEnabler(newBody)
  95. oldBody.parentNode.replaceChild(newBody, oldBody)
  96. }
  97. }
  98. }, BODY_DELAY)
  99. }
  100.  
  101. function appendScript(documentObject) {
  102. if(!documentObject) {
  103. return
  104. }
  105. var s = documentObject.createElement('script')
  106. s.innerHTML = '(' + enableSelectClickCopy.toString() + ')()'
  107. var container = documentObject.head || documentObject.body
  108. if(container) {
  109. container.appendChild(s)
  110. }
  111. }
  112.  
  113. function prependScriptTo(container) {
  114. if(!container) {
  115. return
  116. }
  117. var s = document.createElement('script')
  118. s.innerHTML = '(' + enableSelectClickCopy.toString() + ')()'
  119. container.insertBefore(s, container.firstChild)
  120. }
  121.  
  122. function appendCssEnabler(container) {
  123. var css = document.createElement('style')
  124. css.type = 'text/css'
  125. css.innerHTML =
  126. '* {-webkit-touch-callout: text !important; -webkit-user-select: text !important; ' +
  127. '-khtml-user-select: text !important; -moz-user-select: text !important; ' +
  128. '-ms-user-select: text !important; user-select: text !important;}'
  129. if(container) {
  130. container.appendChild(css)
  131. }
  132. }
  133.  
  134. init()
  135.  
  136. if ('onbeforescriptexecute' in document) {
  137. //for firefox
  138. document.addEventListener('beforescriptexecute', loadedHandler, true)
  139. }
  140. else {
  141. //for chrome and opera
  142. document.addEventListener('beforeload', loadedHandler, true)
  143. }
  144.  
  145. document.addEventListener('DOMContentLoaded', function() {
  146. //in case all previous efforts fail
  147. loadedHandler()
  148. //handle css and iframes
  149. loadedCssIframeHandler()
  150. }, true)