🏠 Home 

Original Content

Automatically redirect content stealing websites to their original counterparts

  1. // ==UserScript==
  2. // @name Original Content
  3. // @namespace http://xmine128.tk/gm/original-content/
  4. // @description Automatically redirect content stealing websites to their original counterparts
  5. // @require https://cdnjs.cloudflare.com/ajax/libs/xregexp/2.0.0/xregexp-min.js
  6. // @license GPL-3.0+
  7. // @include *://*.bigresource.com/*
  8. // @include *://*.techforumnetwork.com/*
  9. // @include *://techforumnetwork.com/*
  10. // @include *://*.linuxine.com/story/*
  11. // @include *://linuxine.com/story/*
  12. // @include *://*.forumsee.com/*
  13. // @include *://forumsee.com/*
  14. // @include *://*.bighow.net/*
  15. // @include *://bighow.net/*
  16. // @include *://*.techassistbox.com/*
  17. // @include *://techassistbox.com/*
  18. // @include *://*.youku.io/*
  19. // @include *://youku.io/*
  20. // @icon http://xmine128.tk/gm/original-content/icon.jpg
  21. // @version 1.1.3
  22. // @grant GM_xmlhttpRequest
  23. // @run-at document-start
  24. // ==/UserScript==
  25. 'use strict';
  26. /**
  27. * The icon has been released by the user "Nisha A" on Flickr under the CC-BY license
  28. *
  29. * Image on Flickr: https://www.flickr.com/photos/samiksha/445070705/sizes/o/in/photostream/
  30. * Created by user: https://www.flickr.com/photos/samiksha/
  31. */
  32. const URL = window.location.href;
  33. /**
  34. * Call the given callback function at the given time during page load
  35. *
  36. * Note: This function assumes that it is being called during "document-start"!
  37. *
  38. * @param {Function} callback
  39. * The function to call
  40. * @param {String} run_at
  41. * During what stage of the page load the function should be called ("document-start", "document-end" or "load")
  42. * @param {Object} ...
  43. * Additional parameters to pass to the callback function
  44. */
  45. function _callback_run_at(callback, run_at)
  46. {
  47. // Read the additonal parameters
  48. var params = Array.prototype.slice.call(arguments, 2);
  49. switch(run_at) {
  50. case 'document-start':
  51. Function.prototype.apply.call(callback, null, params);
  52. break;
  53. case 'load':
  54. window.addEventListener("load", function()
  55. {
  56. Function.prototype.apply.call(callback, null, params);
  57. }, false);
  58. break;
  59. default:
  60. document.addEventListener("DOMContentLoaded", function()
  61. {
  62. Function.prototype.apply.call(callback, null, params);
  63. }, false);
  64. }
  65. }
  66. /**
  67. * Process a single URL rewrite rule
  68. *
  69. * If `rewriter` is a function then it will receive the following parameters:
  70. * - URL: The URL of the current page
  71. * - r###lt: The r###lt of the regular expression matching operation
  72. *
  73. * @param {RegExp|String} regexp
  74. * The regular expression that must be match by the current page URL
  75. * @param {Function|String} rewriter
  76. * A function or XRegExp rewrite string used for replacing the URL
  77. */
  78. function rule_url(regexp, rewriter)
  79. {
  80. var r###lt = URL.match(regexp);
  81. if(r###lt) {
  82. var href = null;
  83. if(typeof(rewriter) == 'function') {
  84. href = rewriter(URL, r###lt);
  85. } else {
  86. // Rewrite URL using XRegExp :-)
  87. href = XRegExp.replace(URL, regexp, rewriter);
  88. }
  89. // Prevent page load
  90. //TODO: Get this to do anything more blanking the page
  91. var interval = window.setInterval(function()
  92. {
  93. document.documentElement.innerHTML = "";
  94. }, 1);
  95. document.addEventListener("DOMContentLoaded", function(event)
  96. {
  97. clearInterval(interval);
  98. });
  99. // Rewrite URL
  100. window.location.replace(href);
  101. }
  102. }
  103. /**
  104. * Follow a hyperlink on a page
  105. *
  106. * @param {RegExp|String} regexp
  107. * The regular expression that must be match by the current page URL
  108. * @param {Function|String} selector
  109. * A function or XRegExp rewrite string used to generated to selector of the element to click on
  110. * @param {String} [run_at="document-end"]
  111. * When to perform the action ("document-start", "document-end" or "load")
  112. */
  113. function rule_link(regexp, selector, run_at)
  114. {
  115. var r###lt = URL.match(regexp);
  116. if(r###lt) {
  117. if(typeof(selector) == 'function') {
  118. selector = selector(URL, r###lt);
  119. } else {
  120. // Rewrite URL using XRegExp
  121. selector = XRegExp.replace(URL, regexp, selector);
  122. }
  123. // Click at the correct stage during page load
  124. _callback_run_at(function(selector)
  125. {
  126. window.location.replace(document.querySelector(selector).href);
  127. }, (run_at || "document-end"), selector);
  128. }
  129. }
  130. /**
  131. * Process a single URL action rule
  132. *
  133. * If `callback` is a function then it will receive the following parameters:
  134. * - URL: The URL of the current page
  135. * - r###lt: The r###lt of the regular expression matching operation
  136. * If `callback` is a string then that string will be executed in the page's context
  137. *
  138. * @param {RegExp|String} regexp
  139. * The regular expression that must be match by the current page URL
  140. * @param {Function|String} callback(URL)
  141. * The function to call when the page URL matches the given regex
  142. * @param {String} [run_at="document-end"]
  143. * When to perform the action ("document-start", "document-end" or "load")
  144. */
  145. function rule_action(regexp, callback, run_at)
  146. {
  147. var r###lt = URL.match(regexp);
  148. if(r###lt) {
  149. // Create wrapper function for string callback
  150. if(typeof(callback) == "string") {
  151. var code = callback;
  152. callback = function()
  153. {
  154. window.location.href = "javascript:" + code;
  155. }
  156. }
  157. // Execute callback function at the correct stage during page load
  158. _callback_run_at(callback, (run_at || "document-end"), URL, r###lt);
  159. }
  160. }
  161. rule_url(/^http[s]?:\/\/([^.]+)\.bigresource\.com\/(?:[^-]+[-])+[-]?([A-Za-z0-9]{9,})\.html$/i, "http://$1.bigresource.com/Track/$2/");
  162. rule_url(/^http[s]?:\/\/(?:[^.]+\.)*bighow\.net\/(\d+)-([^.]+)\.html$/i, "http://bighow.net/track/$1/$2");
  163. rule_link(/^http[s]?:\/\/(?:[^.]+\.)*linuxine\.com\/story\/.+$/i, "a.pviewlink");
  164. rule_link(/^http[s]?:\/\/(?:[^.]+\.)*forumsee\.com\/.+$/i, "a.bigLink");
  165. rule_link(/^http[s]?:\/\/(?:[^.]+\.)*youku\.io\/.+$/i, "#a_text > .pub_info > a");
  166. rule_action(/^http[s]?:\/\/(?:[^.]+\.)*techforumnetwork\.com\/techqns\/[a-z0-9-]+\/$/i, "readPost()", "document-end");
  167. rule_action(/^http[s]?:\/\/(?:[^.]+\.)*techassistbox\.com\/[A-Za-z0-9-]+_\d+[.]html$/i, function()
  168. {
  169. var id = document.querySelector("#answerQuestion > button").onclick.toString().match(/v_th\(['"]([A-Za-z0-9]+)['"]\)/i)[1];
  170. window.location.replace("http://www.techassistbox.com/goto/" + id + "/");
  171. });