Select-click-copy Enabler

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

目前为 2017-05-14 提交的版本,查看 最新版本

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