EnstylerJS

MyDealz Enstyler Frontend and enhanced features

目前为 2016-11-09 提交的版本。查看 最新版本

  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.11.093
  8. // @grant GM_getValue
  9. // @grant GM_setValue
  10. // @grant GM_log
  11. // @grant GM_xmlhttpRequest
  12. // @require http://code.jquery.com/jquery-3.1.1.min.js
  13. // @require http://cdnjs.cloudflare.com/ajax/libs/jquery-throttle-debounce/1.1/jquery.ba-throttle-debounce.min.js
  14. // @require http://openuserjs.org/src/libs/sizzle/GM_config.js
  15. // ==/UserScript==
  16.  
  17. // ========== INIT EnstylerJS =====================================
  18. // init Enstyler environment
  19. var enUserLogin = false;
  20. var enUserName = '';
  21.  
  22. function EnstylerInit () {
  23. // hide Enstyler2 CSS (c) text because we have a button now
  24. addStyleString('.threadWidget-footer::after {display: none !important};');
  25. EnstylerButtonCreate();
  26. // basic config panel formatting, everything else is formatted by enstyler
  27. var enCSS = ['#GM_config {left: 5% !iportant; top: 9% !important; height: auto !important; max-width: 35em !important;}',
  28. '#GM_config input, #GM_config button { border: 1px solid; margin: 0.5em 0em 0.2em 1em; padding: 0.1em;}',
  29. '#GM_config .reset { font-size: 9pt; padding-right: 1em; }',
  30. '#GM_config_enstyler_var:after {content: ". <- please install actual CSS!"; font-weight: bold;}',
  31. '.enClassHidden {display: none;}',
  32. ].join(" ");
  33. addStyleString(enCSS);
  34. // get LoginStatus and Username
  35. if (enUserLogin = $('.avatar--type-nav').length) {
  36. enUserName = $('.navDropDown a').attr('href');
  37. enUserName = enUserName.replace(/.*\profile\/(.+)\/overview$/,'$1');
  38. }
  39. }
  40.  
  41.  
  42. function EnstylerStart () {
  43. // ============ stuff to modify page content =============================
  44.  
  45. // REGEX to detect external URL
  46. var REGEX_THREAD = /^https?:\/\/www\.mydealz\.de\/visit\/thread(image)?\/\d+$/;
  47. var REGEX_DESC = /^https?:\/\/www\.mydealz\.de\/visit\/threaddesc\/\d+\/\d+$/;
  48. var REGEX_COMMENT = /^https?:\/\/www\.mydealz\.de\/visit\/comment\/\d+\/\d+$/;
  49. var REGEX_AMAZONMOB = /^https?:\/\/www\.amazon\..*\/gp\/aw\/.*$/;
  50. //var REGEX_AMAZON = /^https?:\/\/www\.amazon\..*$/;
  51.  
  52. //* GM_xmlhhtpREquest not supported by firefox mobile :-(((
  53. // abfangen aller links mit jQuery
  54. $('a').bind('click', function(){
  55. var url = this.href;
  56.  
  57. // externer Link mit Redirect ...
  58. // Match REDIRECT URLs and open new Window with finalUrl
  59. if (GM_config.get('enConfFilterLink') && url.match(REGEX_THREAD) || url.match(REGEX_DESC) || url.match(REGEX_COMMENT)) {
  60. // Workaround: pre open window because of popup blockers
  61. var asyncWindow = window.open(url, '_blank');
  62. // now lookup redirecd external URL ...
  63. // alert("external URL detected");
  64. GM_xmlhttpRequest({
  65. method: 'GET',
  66. url: url,
  67. // here we get the final URL from redirect
  68. onload: function (response) {
  69. // process final URL
  70. var newUrl = response.finalUrl;
  71. //alert(newUrl);
  72. // lets see ...
  73. if (newUrl.match(REGEX_AMAZONMOB)) {
  74. newUrl = newUrl.replace("/gp/aw/d/", "/dp/");
  75. newUrl = newUrl.replace("/gp/aw/ol/", "/gp/offer-listing/");
  76. //alert("Amazon rewritten URL: " + newUrl);
  77. }
  78. // load processed URL in preopened window
  79. asyncWindow.location = newUrl;
  80. }
  81. });
  82. // return without link processing by Browser
  83. return false;
  84. }
  85. // return with link processing in Browser
  86. return true;
  87. }); // - END GM_xmlhttpRequest */
  88. } // END EnstylerStart
  89.  
  90.  
  91.  
  92. // add actions to tread overview @ some places ==================================
  93. function EnstylerDealActions() {
  94. // if logged in ...
  95. if (enUserLogin) {
  96. // code used for MyDealz Dealz actions, thanks to mydealz :-)
  97. var myOuterHtml = [ '<span class="js-options bg--em bRad--a space--h-3 space--v-3 space--mt-3 text--b">', '</span>'];
  98. var enDealAction = [ '<a class="link ico ico--pos-l ico--type-comment-blue space--mr-3"', // comment 0+1
  99. 'href="<ENSTYLER-HREF-HERE>#comment-form" data-handler="track" data-track="{&quot;action&quot;:&quot;scroll_to_comment_add_form&quot;,&quot;label&quot;:&quot;engagement&quot;}">Sag was dazu</a>',
  100. '<a class="link text--color-blue ico ico--type-bookmark-blue ico--pos-l space--mr-3"', //un-bookmark 2+3
  101. 'data-handler="track replace" data-replace="{&quot;endpoint&quot;:&quot;https:\/\/www.mydealz.de\/threads\/<ENSTYLER-THREADID-HERE>/remove&quot;,&quot;method&quot;:&quot;post&quot;}" data-track="{&quot;action&quot;:&quot;save_thread&quot;,&quot;label&quot;:&quot;engagement&quot;}"> Von Liste entfernen</a>',
  102. '<a class="link text--color-blue ico ico--type-pencil-blue ico--pos-l space--mr-3"', // edit 4+5
  103. 'href="<ENSTYLER-HREF-HERE>/edit" data-handler="track" data-track="{&quot;action&quot;:&quot;goto_thread_edit_form&quot;,&quot;beacon&quot;:true}">Bearbeiten</a>',
  104. '<a class="thread-expire link ico ico--type-clock-blue ico--pos-l space--mr-3"', // expiried not working :-(
  105. 'href="<ENSTYLER-HREF-HERE>/expire/report" rel="nofollow" data-handler="track replace" data-track="{&quot;action&quot;:&quot;report_expired_thread&quot;,&quot;label&quot;:&quot;contribution&quot;}" data-replace="{&quot;endpoint&quot;:&quot;https:\/\/www.mydealz.de\/<ENSTYLER-HREF-HERE>/expire\/report&quot;}">Abgelaufen?</a>',
  106. ];
  107. var PATTERN = [ /<ENSTYLER-HREF-HERE>/g, // pattern to replace by deal link ...
  108. /<ENSTYLER-THREADID-HERE>/g, // pattern to replace ID
  109. ]
  110. if (GM_config.get('enConfMoreDeal')) {
  111. var parser = location; // parse location
  112. var pathname = parser.pathname;
  113. var username = pathname.replace(/.*profile\//,'');
  114. username = username.replace(/\/.*/,'');
  115. // no username ??
  116. if (username == "") {
  117. username = "unknown";
  118. } else {
  119. pathname = pathname.replace(username + '/',''); // remove username if path is longer
  120. }
  121. //alert("username:" + username + " pfadname:" +pathname)
  122. // default for all Dealz: comment
  123. var myAction = enDealAction[0]+ enDealAction[1];
  124.  
  125. // Action for special locations only ===========
  126. // saved Dealz panel
  127. if (pathname.endsWith('profile/saved-deals') ){
  128. // add for user saved-dealz: un-bookmark
  129. myAction += enDealAction[2]+ enDealAction[3];
  130. }
  131. if (pathname.endsWith('profile/diskussion') || pathname.endsWith(username)){
  132. // add user dealz and discussions: comment edit
  133. myAction += enDealAction[4]+ enDealAction[5];
  134. }
  135.  
  136. // we have an Action to add to an Deal!
  137. if (myAction != "") {
  138. //GM_log('Action:' + myAction);
  139. // every thread on thread page ...
  140. $('article').each(function () {
  141. // get ThreadID, Link to Deal and DealID
  142. var myThread = $(this).attr('id');
  143. if (!myThread.startsWith('thread_')) {return;}
  144. var myDealHref = $('#' + myThread + ' .thread-title a').attr('href');
  145. var myDealID = myThread.replace('thread_','')
  146. if (myThread.startsWith('To be')) {return;}
  147. // compose final HTML
  148. var newHtml= myOuterHtml[0] + myAction + myOuterHtml[1];
  149. newHtml = newHtml.replace(PATTERN[0], myDealHref);
  150. newHtml = newHtml.replace(PATTERN[1], myDealID);
  151. // append HTML to Deal
  152. $('#' + myThread +' .thread-infoRow').each(function () {
  153. $(this).append(newHtml);
  154. $(this).removeClass('thread-infoRow');
  155. });
  156. });
  157. }
  158. // actions for everywhere ===========
  159. // remove unwanted HTML from deal description
  160. $('.thread--type-detail .userHtml').each(function () {
  161. // userhtml code from mydalz, need to find jafascript to save automatically :-(
  162. var enUserhtml = ['<div class="userHtml overflow--wrap-break space--t-3" data-handler="lightbox-xhr" data-lightbox-xhr="{&quot;name&quot;:&quot;threads&quot;}">',
  163. '</div>', // sourround deal description
  164. ];
  165. // get inner html
  166. var myHtml = $(this).html();
  167.  
  168. // remove unwanted Stuff: combined <div><br><br> stuff, created by cut'npaste html
  169. // not elegant, but works ...
  170. var newHtml = myHtml.replace(/<div>|<div><br>|<\/br>|<\/div>/gi,'');
  171. newHtml = newHtml.replace(/<br><br><br>|<br><br><br><br>|<br><br><br><br><br>/gi,'<br><br>');
  172. // replace original with modifyed html
  173. $(this).replaceWith(enUserhtml[0] + newHtml + enUserhtml[1]);
  174. });
  175.  
  176. } // END enabled
  177. }
  178. }
  179.  
  180.  
  181. // show popup user info while click on avatar ... ======================
  182. function EnstylerAvatarPopup() {
  183. // if logged in ...
  184. if (enUserLogin) {
  185. // code used for MyDealz avatar popup, thanks to mydealz :-)
  186. var enPopupUser = ['<button data-handler="track popover" data-track="{&quot;action&quot;:&quot;show_short_user_profile&quot;,&quot;label&quot;:&quot;engagement&quot;}"data-popover="{&quot;endpoint&quot;:&quot;',
  187. '/short&quot;,&quot;target&quot;:&quot;#template-popoverLoader&quot;,&quot;layout&quot;:[{&quot;preset&quot;:&quot;e&quot;,&quot;y&quot;:&quot;50%&quot;,&quot;left&quot;:{&quot;offset&quot;:0},&quot;width&quot;:300,&quot;maxWidth&quot;:&quot;100%&quot;}]}">',
  188. '</button>',
  189. ];
  190. // remove second image from cardview
  191. if (GM_config.get('enConfUser')) { addStyleString('.thread-footer-cell a img.avatar.vAlign--all-m.space--mr-1.thread-avatar {display: none;}'); }
  192.  
  193. // replace every avatar link without popup
  194. if (GM_config.get('enConfUser')) {
  195. $('.thread-footer-cell a.user.linkPlain, .user.linkPlain.thread-user').each(function () {
  196. var Iam = $(this);
  197. // get inner html and link to user profile
  198. var myHtml = Iam.html();
  199. var mysrc = Iam.attr('href');
  200. // seperate user name from image and add class user
  201. var myAvatar1 = myHtml.replace(/<span.*/,'');
  202. var myAvatar2 = myHtml.replace(/.*<span class=".* space--mr-1">/,'<span class=" space--mr-1 user link-plain">');
  203.  
  204. // show small / medium sized Avatar
  205. myAvatar1 = myAvatar1.replace('avatar--type-s','avatar--type-m'); //in Dealz
  206. if (GM_config.get('enConfAvatar')) { myAvatar1 = myAvatar1.replace('thread-avatar','avatar--type-m'); }
  207. // compose popup
  208. var myPopup = enPopupUser[0] + Iam.attr('href') + enPopupUser[1] + myAvatar1 + enPopupUser[2] + '<a href="' + Iam.attr('href') + '">'+ myAvatar2 + '</a>';
  209. Iam.replaceWith(myPopup);
  210. });
  211. }
  212. }
  213. }
  214.  
  215.  
  216.  
  217. // create select page or scrollwheel for page navigation =============
  218. var EnstylerPageEnum='enPageEnum';
  219. var selectList = document.createElement("select");
  220. selectList.id = EnstylerPageEnum;
  221. selectList.onchange = EnstylerPageAction;
  222.  
  223. var EnstylerPageEnumDown='enPageEnumDown';
  224. var selectListDown = document.createElement("select");
  225. selectListDown.id = EnstylerPageEnumDown;
  226. selectListDown.onchange = EnstylerPageAction;
  227.  
  228. function EnstylerPagePickerCreate() {
  229. // if enabled
  230. if (GM_config.get('enConfPagePicker')) {
  231. // init values and clear select list
  232. var page=1;
  233. var min=1;
  234. var max=1;
  235. $(selectList).empty();
  236. // get page and max from pagenav
  237. if ( $('.text--color-charcoalTint').length ) {
  238. // remove linebreaks
  239. pageHtml = $('.text--color-charcoalTint').html().replace(/\r?\n|\r/g);
  240. //locate actual page and last page
  241. page = pageHtml.replace( /.*>Seite /i ,''); page = page.replace( /<.*/i , '');
  242. max = pageHtml.replace( /.*page=/ ,''); max = max.replace( /[^0-9].*/i , '');
  243. if (page == '') {page=1;}
  244. if (max == '') {max=page;}
  245. }
  246.  
  247. // create page select element
  248. var x; var last; var option;
  249.  
  250. for (x = min; x <= max; ) {
  251. option = document.createElement("option");
  252. option.text = x;
  253. selectList.add(option); //selectListDown.add(option);
  254. last = x;
  255. // non linear increment
  256. var diff = Math.abs(x-page);
  257.  
  258. if ( x < 10 || diff < 5) { x++; }
  259. else if ( x < 1000 && diff > 600) { x += Math.floor(diff/100); }
  260. else { x += Math.floor(diff/2); }
  261. }
  262. // add last page
  263. if (page > max) { max=page;}
  264. if (last < max ) {
  265. option = document.createElement("option");
  266. option.text = max;
  267. selectList.add(option); //selectListDown.add(option);
  268. }
  269. // set default value
  270. selectList.value = page; //selectListDown.value = page;
  271.  
  272. // Deal Page
  273. if ($('.voteBar').length) {
  274. selectList.setAttribute('class', 'subNavMenu-link subNavMenu-btn voteBar--sticky-off--hide');
  275. $('.voteBar--sticky-off--hide:last').before(selectList);
  276. } else {
  277. // overwiew page
  278. if (GM_config.get('enConfBtn')) {
  279. // Place Picker in subnav
  280. selectList.setAttribute('class', 'box--all-i subNavMenu-link subNavMenu-btn');
  281. $('.subNav-label:last').before(selectList);
  282. } else {
  283. //place picker in MainNav
  284. selectList.setAttribute('class', 'js-navDropDown-messages vAlign--all-m');
  285. if ($('.test-loginButton').length) {
  286. $('.test-loginButton').before(selectList);
  287. } else {
  288. $('.js-navDropDown-messages').before(selectList);
  289. }
  290. }
  291. }
  292. }
  293. }
  294.  
  295. // goto selected Page
  296. function EnstylerPageAction() {
  297. var enPage = 'page=' + $(this).val();
  298. var enUrl = window.location.href;
  299. var path = window.location.pathname;
  300.  
  301. // remove page= and everthing behind
  302. enUrl = enUrl.replace( /page=.*|#.*/ ,'');
  303. // add new page parameter
  304. if ( enUrl.endsWith('?') || enUrl.endsWith('&')) {
  305. enUrl += enPage;
  306. } else {
  307. enUrl += '?'+enPage;
  308. }
  309. // add #thread-comments for deal
  310. if (path.startsWith('/deals/')) { enUrl += '#thread-comments';}
  311. //alert( 'Seite: '+ enPage + ' URL: ' +enUrl );
  312. window.location = enUrl;
  313. }
  314.  
  315. function EnstylerPagePickerRemove() {
  316. // Removes pagepicker from the document
  317. $('#'+ EnstylerPageEnum).remove();
  318. }
  319.  
  320.  
  321.  
  322. // blacklist do not show dealz containing blacklistet words ==========================
  323. // search in kategorie, dealtitle, and username
  324. var enClassHidden = 'enClassHidden';
  325. var enUnblackText = 'unBlacklist <NUM-BLACK> Dealz'
  326.  
  327. function EnstylerBlacklist() {
  328. // if logged in and user is not in whitelist
  329. if (enUserLogin && ! GM_config.get('enConfWhitelist').includes(enUserName)) {
  330. // add actual user to whitelist
  331. GM_config.set('enConfWhitelist', '@'+enUserName +',' + GM_config.get('enConfWhitelist'));
  332. }
  333. var enBlacklisted=0;
  334. // Black/Whitelist active
  335. if (GM_config.get('enConfBlackEnable')) {
  336. var unwantedRegex = [ /[\[\]\(\)\{\}\?\.\:\;\!\"\*\+\ ]/g, // in White/Backlist
  337. /[\[\]\(\)\{\}\?\.\:\;\!\"\*\+\,]/g // in Dealtext
  338. ];
  339. // convert Black/Whitelist to Array
  340. var myTemp=GM_config.get('enConfBlacklist');
  341. myTemp = myTemp.replace(unwantedRegex[0], '');
  342. var enBlack = myTemp.split(',');
  343. myTemp=GM_config.get('enConfWhitelist');
  344. myTemp = myTemp.replace(unwantedRegex[0], '');
  345. var enWhite = myTemp.split(',');
  346.  
  347. // process every article
  348. $('article').each(function () {
  349. // get thrad and return if no deal
  350. var myThread = $(this).attr('id');
  351. if (!myThread.startsWith('thread_')) {return;}
  352. // get title, categorie, user
  353. var myDealText = $('#' + myThread + ' .thread-category').text();
  354. myDealText += ' ' +$('#' + myThread + ' .thread-title a').text();
  355. myDealText += ' @' +$('#' + myThread + ' .user').text();
  356. myDealText = myDealText.replace(unwantedRegex[1] ,' ');
  357. // Whitelist first
  358. for (var i=-1, length=enWhite.length; ++i < length;) {
  359. // whitelist Regex, exit if found
  360. //alert('White: '+ enWhite[i]);
  361. if (enWhite[i] !='' && myDealText.match(new RegExp(enWhite[i],'i'))) {
  362. alert(myDealText +' WHITE /'+ enWhite[i]+'/i');
  363. return;
  364. }
  365. }
  366. // blacklist first, blacklist if found and exit
  367. for (var i=-1, length=enBlack.length; ++i < length;) {
  368. // whitelist Regex, unwanted characteres are already removed
  369. if (enBlack[i] !='' && myDealText.match(new RegExp(enBlack[i],'i'))) {
  370. //alert(myDealText +' BLACK /'+ enBlack[i]+'/i');
  371. $(this).addClass(enClassHidden);
  372. enBlacklisted++;
  373. return;
  374. }
  375. }
  376. }); // END Article
  377. // set label for unBlacklist button
  378. fieldDefs.enConfUnblacklist.label=enUnblackText.replace('<NUM-BLACK>',enBlacklisted)
  379. //alert('BLACK:' + enBlacklisted)
  380. }
  381. }
  382.  
  383. function EnstylerBlacklistRemove() {
  384. $('.'+enClassHidden).removeClass(enClassHidden);
  385. }
  386.  
  387.  
  388. // create button for display Config ==============
  389. var EnstylerButton = 'EnstylerButton';
  390.  
  391. //var input = document.createElement('a');
  392. // input.setAttribute('href', 'showEnstylerConfig()');
  393. // input.setAttribute('id', EnstylerButton);
  394. var input = document.createElement('input');
  395. input.type = 'button';
  396. input.value = 'Enstyler';
  397. input.setAttribute('id', EnstylerButton)
  398. input.onclick = showEnstylerConfig;
  399.  
  400. function EnstylerButtonCreate() {
  401. // add Enstyler Button to ...
  402. var myElement;
  403. if (GM_config.get('enConfBtn') && $(window).width() > GM_config.get('enConfBtnMinWidth')) {
  404. // add button to MainNav
  405. var Elements = document.getElementsByClassName("nav-link");
  406. myElement = Elements[3];
  407. input.setAttribute('class', 'vAlign--all-m nav-link-text');
  408. input.setAttribute('style', '');
  409. } else {
  410. // add button to SubNav
  411. myElement = document.getElementById('tour-filter');
  412. input.setAttribute('class', 'box--all-i subNavMenu-link');
  413. input.setAttribute('style', 'font-size: 1.28571em; font-weight: 700; top: 3px; left: -0.7em');
  414. }
  415. // only if myElement exist
  416. if (myElement !== null) {
  417. myElement.appendChild(input);
  418. //insertAfter(input, myElement);
  419. }
  420. }
  421.  
  422. function EnstylerButtonRemove() {
  423. // Removes button from the document
  424. $('#'+ EnstylerButton).remove();
  425. }
  426.  
  427.  
  428.  
  429. // ============= GM_config functions =======================================
  430.  
  431.  
  432. // define GM_config elements
  433. var fieldDefs = {
  434. // Part one: load external content --------
  435. 'enstyler': {
  436. 'section': ['additonal features for Enstyler', ''],
  437. 'label': 'Install / Update CSS...', // Appears on the button
  438. 'type': 'button', // Makes this setting a button input
  439. 'click': function() { // Function to call when button is clicked
  440. showUrl('https://userstyles.org/styles/128262#style-info'); }
  441. },
  442.  
  443. 'dontCookies': {
  444. 'label': 'Mozilla no cookies...', // Appears on the button
  445. 'type': 'button', // Makes this setting a button input
  446. 'click': function() { // Function to call when button is clicked
  447. showUrl('https://addons.mozilla.org/de/addon/i-dont-care-about-cookies/'); }
  448. },
  449.  
  450. //* thhis has to be the last one,display only if internal version is disabled
  451. 'externalMobileRedirect': {
  452. 'label': 'Amazon mobile redirect...', // Appears on the button
  453. 'type': 'button', // Makes this setting a button input
  454. 'click': function() { // Function to call when button is clicked
  455. showUrl('https://greasyfork.org/de/scripts/19700'); }
  456. }, // */
  457.  
  458. // part two: EnstylerJS internal configuration options ------
  459. 'hidden1': { // display next section, dont kow why ...
  460. 'section': ['Configuration', ''],
  461. 'type': 'hidden', // Makes this setting a hidden input
  462. 'value': 'Some hidden value' // Value stored
  463. },
  464.  
  465. // postion of enstyler "button"
  466. 'enConfBtn': {
  467. 'label': 'Show Enstyler in MainNav', // Appears next to field
  468. 'type': 'checkbox', // Makes this setting a checkbox input
  469. 'default': false // Default value if user doesn't change it
  470. },
  471. 'enConfBtnMinWidth': {
  472. 'label': 'only if width is bigger than ', // Appears next to field
  473. 'type': 'int', // Makes this setting a text input
  474. 'min': 600, // Optional lower range limit
  475. 'max': 1200, // Optional upper range limit
  476. 'size': 4, // Limit length of input (default is 25)
  477. 'default': 850 // Default value if user doesn't change it
  478. },
  479.  
  480. // ehanced USerInfo
  481. 'enConfUser': {
  482. 'label': 'Show Popuop Userinfo', // Appears next to field
  483. 'type': 'checkbox', // Makes this setting a checkbox input
  484. 'default': true // Default value if user doesn't change it
  485. },
  486. 'enConfAvatar': {
  487. 'label': 'bigger Avatar for Popuop', // Appears next to field
  488. 'type': 'checkbox', // Makes this setting a checkbox input
  489. 'default': true // Default value if user doesn't change it
  490. },
  491. // enable filtering of external links
  492. 'enConfFilterLink': {
  493. 'label': 'Amazon mobile redirect', // Appears next to field
  494. 'type': 'checkbox', // Makes this setting a checkbox input
  495. 'default': true // Default value if user doesn't change it
  496. }, // */
  497.  
  498. // more Deal actions
  499. 'enConfMoreDeal': {
  500. 'label': 'additional Deal actions', // Appears next to field
  501. 'type': 'checkbox', // Makes this setting a checkbox input
  502. 'default': true // Default value if user doesn't change it
  503. },
  504.  
  505. // Page picker
  506. 'enConfPagePicker': {
  507. 'label': 'Enable Page Picker', // Appears next to field
  508. 'type': 'checkbox', // Makes this setting a checkbox input
  509. 'default': false // Default value if user doesn't change it
  510. },
  511. // Black/Whitelist input
  512. 'enConfBlackEnable': {
  513. 'label': 'Enable Black- / Whitelist', // Appears next to field
  514. 'type': 'checkbox', // Makes this setting a checkbox input
  515. 'default': true // Default value if user doesn't change it
  516. },
  517. 'enConfBlacklist': {
  518. 'label': 'Blacklist - deals, categories, @users', // Appears next to field
  519. 'type': 'text', // Makes this setting a text input
  520. 'size': 70, // Limit length of input (default is 25)
  521. 'default': 'Nutella, Bangood, @Admin' // Default value if user doesn't change it
  522. },
  523. 'enConfWhitelist': {
  524. 'label': 'Whitelist', // Appears next to field
  525. 'type': 'text', // Makes this setting a text input
  526. 'size': 70, // Limit length of input (default is 25)
  527. 'default': '' // Default value if user doesn't change it
  528. },
  529. 'enConfUnblacklist': {
  530. 'label': 'UnBlacklist', // Appears on the button
  531. 'type': 'button', // Makes this setting a button input
  532. 'click': function() { // Function to call when button is clicked
  533. EnstylerBlacklistRemove(); }
  534. },
  535. // display copy message at end of section ...
  536. 'copy': {
  537. '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>'],
  538. 'type': 'hidden', // Makes this setting a hidden input
  539. 'value': 'Some hidden value' // Value stored
  540. },
  541.  
  542. };
  543.  
  544.  
  545. // display GM_copnfig as div, so we cam apply CSS!!
  546. var enGMOptChange = false;
  547. var enGMFrame = document.createElement('div');
  548. document.body.appendChild(enGMFrame);
  549.  
  550. GM_config.init(
  551. {
  552. id: 'GM_config',
  553. title: 'EnstylerJS - Settings',
  554. fields: fieldDefs,
  555. 'events': // Callback functions object
  556. {
  557. //'init': function() { alert('onInit()'); },
  558. // remove elements ich switch is checked or not
  559. 'open': function() {
  560. var enRemoveConfig = [
  561. { check: true, switch: 'enConfFilterLink', remove: 'externalMobileRedirect'},
  562. { check: false, switch: 'enConfBtn', remove: 'enConfBtnMinWidth'},
  563. { check: false, switch: 'enConfUser', remove: 'enConfAvatar'},
  564. { check: false, switch: 'enConfBlackEnable', remove: 'enConfWhitelist'},
  565. { check: false, switch: 'enConfBlackEnable', remove: 'enConfBlacklist'},
  566. { check: false, switch: 'enConfBlackEnable', remove: 'enConfUnblacklist'}
  567. ];
  568. $(enRemoveConfig).each(function() {
  569. if (GM_config.get(this.switch) == this.check) {
  570. GM_config.fields[this.remove].remove();
  571. }
  572. });
  573. },
  574. //'reset': function() { enGMOptChange = true; },
  575. // relaod page on close after save
  576. 'save': function() {
  577. EnstylerButtonRemove();
  578. EnstylerButtonCreate();
  579. EnstylerPagePickerRemove();
  580. EnstylerPagePickerCreate();
  581. EnstylerBlacklistRemove()
  582. EnstylerBlacklist();
  583. },
  584. //'close': function() { if (enGMOptChange) { location.reload(); enGMOptChange = false;} },
  585. },
  586. 'frame': enGMFrame // Element used for the panel
  587. }
  588. );
  589.  
  590.  
  591. // EnstylerJS Config Panel anzeigen
  592. function showEnstylerConfig() {
  593. GM_config.open();
  594. }
  595.  
  596. //=========== Support functions for actual use =======
  597.  
  598. // display website in external window
  599. function showUrl(str) {
  600. var myDeco = "innerheight=800,innerwidth=600";
  601. var myName = "enstyler";
  602. // workaround for not working window.focus(): close an existing window first
  603. // not working on mobile :-(
  604. //var myWindowShow = window.open('', myName, "width=100,height=100").close();
  605. var myWindowShow = window.open(str, myName, myDeco);
  606. }
  607.  
  608. // add CSS in to document
  609. function addStyleString(str) {
  610. var node = document.createElement('style');
  611. node.innerHTML = str;
  612. document.body.appendChild(node);
  613. }
  614.  
  615. // ============== START EnstyerJS =============
  616. EnstylerInit();
  617. EnstylerStart();
  618. EnstylerBlacklist();
  619. EnstylerAvatarPopup();
  620. EnstylerDealActions();
  621. EnstylerPagePickerCreate();
  622.  
  623.  
  624. // track DOM change Events, debounce: wait 500ms after mutiple events
  625. // then re-apply (somse) changes to dynamic loaded content,
  626. $('.fGrid-last2, .thread-list--type-card').bind("DOMSubtreeModified",$.debounce( 500, function(){
  627. //GM_log('DOMSubtreeModified detected!!!');
  628. EnstylerDealActions();
  629. EnstylerAvatarPopup();
  630.  
  631. }));