EnstylerJS

MyDealz Enstyler Frontend and enhanced features

目前为 2016-10-30 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name EnstylerJS
  3. // @namespace Enstyler
  4. // @description MyDealz Enstyler Frontend and enhanced features
  5. // @include http://www.mydealz.de/*
  6. // @include https://www.mydealz.de/*
  7. // @version 2.10.304
  8. // @grant GM_getValue
  9. // @grant GM_setValue
  10. // @grant GM_log
  11. // @grant GM_xmlhttpRequest
  12. // @require http://code.jquery.com/jquery-latest.js
  13. // @require https://openuserjs.org/src/libs/sizzle/GM_config.js
  14. // ==/UserScript==
  15.  
  16. // ========== RUN EnstylerJS =====================================
  17. function EnstylerJS () {
  18.  
  19. // create object for enstyler "Menu Button"
  20. var input = document.createElement('input');
  21. input.type = 'button';
  22. input.value = 'Enstyler';
  23. input.onclick = showEnstylerConfig;
  24.  
  25. // add Enstyler Button to ...
  26. var myElement;
  27. if (GM_config.get('enConfMain')) {
  28. // add button to MainNav
  29. var Elements = document.getElementsByClassName("navMenu-trigger");
  30. myElement = Elements[0];
  31. input.className = 'nav-link-text vAlign--all-m';
  32. } else {
  33. // add button to SubNav
  34. myElement = document.getElementById('tour-filter');
  35. input.className = 'box--all-i subNavMenu-link';
  36. input.setAttribute('style', 'font-size: 1.28571em; font-weight: 700; top: 3px; left: -0.7em');
  37. }
  38. // only if myElement exist
  39. if (myElement !== null) {
  40. myElement.appendChild(input);
  41. }
  42.  
  43. // hide Enstyler2 CSS (c) text because we have a button now
  44. addStyleString('.threadWidget-footer::after {display: none !important};');
  45.  
  46. // basic config panel formatting, everything else is formatted by enstyler
  47. var enCSS = ['#GM_config { left: 5% !important; top: 5% !important; height: auto !important; min-width: 19em; max-width: 33em !important;}',
  48. '#GM_config input[type=button], #GM_config button { border: 1px solid; margin: 0.5em 0em 0.2em 1em; padding: 0.1em;}',
  49. '#GM_config .reset { font-size: 9pt; padding-right: 1em; }',
  50. ].join(" ");
  51. addStyleString(enCSS);
  52. }
  53. // ========= END INIT, we are ready to go ===============================
  54.  
  55. // ============ functions to modify page content =============================
  56.  
  57. // REGEX to detect external URL
  58. var REGEX_THREAD = /^https?:\/\/www\.mydealz\.de\/visit\/thread(image)?\/\d+$/;
  59. var REGEX_DESC = /^https?:\/\/www\.mydealz\.de\/visit\/threaddesc\/\d+\/\d+$/;
  60. var REGEX_COMMENT = /^https?:\/\/www\.mydealz\.de\/visit\/comment\/\d+\/\d+$/;
  61. var REGEX_AMAZONMOB = /^https?:\/\/www\.amazon\..*\/gp\/aw\/.*$/;
  62. //var REGEX_AMAZON = /^https?:\/\/www\.amazon\..*$/;
  63.  
  64. // abfangen aller links mit jQuery
  65. // wird genutzt zum filtern und
  66. $('a').bind('click', function(){
  67. var url = this.href;
  68.  
  69. // externer Link mit Redirect ...
  70. // Match REDIRECT URLs and open new Window with finalUrl
  71. if (GM_config.get('enConfFilterLink') && url.match(REGEX_THREAD) || url.match(REGEX_DESC) || url.match(REGEX_COMMENT)) {
  72. // Workaround: pre open window because of popup blockers
  73. // Workaround: if GM_xmlhttpRequest is not availible
  74. var asyncWindow = window.open(url, '_blank');
  75. //* GM_xmlhhtpREquest not supported by firefox mobile :-(((
  76. // now lookup redirecd external URL ...
  77. // alert("external URL detected");
  78. GM_xmlhttpRequest({
  79. method: 'GET',
  80. url: url,
  81. // here we get the final URL from redirect
  82. onload: function (response) {
  83. // process final URL
  84. var newUrl = response.finalUrl;
  85. //alert(newUrl);
  86. // lets see ...
  87. if (newUrl.match(REGEX_AMAZONMOB)) {
  88. newUrl = newUrl.replace("/gp/aw/d/", "/dp/");
  89. newUrl = newUrl.replace("/gp/aw/ol/", "/gp/offer-listing/");
  90. //alert("Amazon rewritten URL: " + newUrl);
  91. }
  92. // load processed URL in preopened window
  93. asyncWindow.location = newUrl;
  94. }
  95. });
  96. // return without link processing by Browser - END GM_xmlhttpRequest */
  97. return false;
  98. }
  99. // return with link processing in Browser
  100. return true;
  101. });
  102.  
  103. // ============= GM_config functions =======================================
  104.  
  105. // define GM_config elements
  106. var fieldDefs = {
  107. // Part one: load external content --------
  108. 'enstyler': {
  109. 'section': ['additonal features for Enstyler', ''],
  110. 'label': 'Install / Update CSS...', // Appears on the button
  111. 'type': 'button', // Makes this setting a button input
  112. 'click': function() { // Function to call when button is clicked
  113. showUrl('https://userstyles.org/styles/128262#style-info'); }
  114. },
  115.  
  116. /*
  117. 'mobileRedirect': {
  118. 'label': 'Amazon mobile redirect...', // Appears on the button
  119. 'type': 'button', // Makes this setting a button input
  120. 'click': function() { // Function to call when button is clicked
  121. showUrl('https://greasyfork.org/de/scripts/19700'); }
  122. }, // */
  123.  
  124. 'dontCookies': {
  125. 'label': 'Mozilla no cookies...', // Appears on the button
  126. 'type': 'button', // Makes this setting a button input
  127. 'click': function() { // Function to call when button is clicked
  128. showUrl('https://addons.mozilla.org/de/addon/i-dont-care-about-cookies/'); }
  129. },
  130.  
  131. // part two: EnstylerJS internal configuration options ------
  132. 'hidden1': { // display next section, dont kow why ...
  133. 'section': ['Configuration', ''],
  134. 'type': 'hidden', // Makes this setting a hidden input
  135. 'value': 'Some hidden value' // Value stored
  136. },
  137.  
  138. // postion of enstyler "button"
  139. 'enConfMain': {
  140. 'label': 'Enstyler in MainNav', // Appears next to field
  141. 'type': 'checkbox', // Makes this setting a checkbox input
  142. 'default': false // Default value if user doesn't change it
  143. },
  144.  
  145. // enable filtering of external links
  146. 'enConfFilterLink': {
  147. 'label': 'Amazon mobile redirect', // Appears next to field
  148. 'type': 'checkbox', // Makes this setting a checkbox input
  149. 'default': true // Default value if user doesn't change it
  150. },
  151. // display copy message at end of section ...
  152. 'copy': {
  153. 'section': ['', '(c) Gnadelwartz - <a target="blank" href="https://www.mydealz.de/diskussion/enstyler2-style-your-mydealz-incl-pepper-sites-736219">Enstyler2 - Style your MyDealz</a>'],
  154. 'type': 'hidden', // Makes this setting a hidden input
  155. 'value': 'Some hidden value' // Value stored
  156. },
  157.  
  158. };
  159.  
  160.  
  161. // display GM_copnfig as div, so we cam apply CSS!!
  162. var frame = document.createElement('div');
  163. document.body.appendChild(frame);
  164.  
  165. GM_config.init(
  166. {
  167. id: 'GM_config',
  168. title: 'EnstylerJS - Settings',
  169. fields: fieldDefs,
  170. // relaod page on close
  171. 'events': // Callback functions object
  172. {
  173. //'init': function() { alert('onInit()'); },
  174. //'open': function() { alert('onOpen()'); },
  175. //'save': function() { alert('onSave()'); },
  176. 'close': function() { location.reload(); },
  177. //'reset': function() { alert('onReset()'); }
  178. },
  179. 'frame': frame // Element used for the panel
  180. }
  181. );
  182.  
  183. // EnstylerJS Config Panel anzeigen
  184. function showEnstylerConfig() {
  185. GM_config.open();
  186. }
  187.  
  188. //=========== Support functions for actual use =======
  189.  
  190. // display website in external window
  191.  
  192. function showUrl(str) {
  193. var myDeco = "innerheight=800,innerwidth=600";
  194. var myName = "enstyler";
  195. // workaround for not working window.focus(): close an existing window first
  196. var myWindowShow = window.open('', myName, "width=100,height=100").close();
  197. myWindowShow = window.open(str, myName, myDeco);
  198. }
  199.  
  200. // add CSS in to document
  201. function addStyleString(str) {
  202. var node = document.createElement('style');
  203. node.innerHTML = str;
  204. document.body.appendChild(node);
  205. }
  206. // sleep time expects milliseconds, then execute code
  207. // NOTE: code runs in parallel (asnyc)!
  208. // Usage!
  209. // sleepAsync(500).then(() => {
  210. // Do something after the sleep!
  211. // });
  212.  
  213. function sleepAsync (time) {
  214. return new Promise((resolve) => setTimeout(resolve, time));
  215. }
  216.  
  217. // ============== INIT EnstyerJS =============
  218. EnstylerJS();
  219.