Enhance titles - Timvision

Hide titles on Timvision website by clicking on a button

当前为 2019-11-01 提交的版本,查看 最新版本

  1. // Enhance titles - Timvision
  2. //
  3. // Hide titles on Timvision website by clicking on a button
  4. //
  5. // https://greasyfork.org/scripts/390632-enhance-titles-timvision
  6. // Copyright (C) 2019, Guido Villa
  7. //
  8. // For information/instructions on user scripts, see:
  9. // https://greasyfork.org/help/installing-user-scripts
  10. //
  11. // --------------------------------------------------------------------
  12. //
  13. // ==UserScript==
  14. // @name Enhance titles - Timvision
  15. // @description Hide titles on Timvision website by clicking on a button
  16. // @version 1.5
  17. // @author guidovilla
  18. // @date 01.11.2019
  19. // @copyright 2019, Guido Villa (https://greasyfork.org/users/373199-guido-villa)
  20. // @license GPL-3.0-or-later
  21. // @homepageURL https://greasyfork.org/scripts/390632-enhance-titles-timvision
  22. // @supportURL https://gitlab.com/gv-browser/userscripts/issues
  23. // @contributionURL https://tinyurl.com/gv-donate-3a
  24. //
  25. // @namespace https://greasyfork.org/users/373199-guido-villa
  26. //
  27. // @match https://www.timvision.it/*
  28. //
  29. // @require https://greasyfork.org/scripts/391648/code/userscript-utils.js
  30. // @require https://greasyfork.org/scripts/390248/code/entry-list.js
  31. // @grant GM_getValue
  32. // @grant GM_setValue
  33. // @grant GM_deleteValue
  34. // @grant GM_listValues
  35. // @grant GM_addStyle
  36. // ==/UserScript==
  37. //
  38. // --------------------------------------------------------------------
  39. //
  40. // To-do (priority: [H]igh, [M]edium, [L]ow):
  41. // - [M] check if title id is really unique for a title or if multiple ids are possible
  42. // - [M] add some @exclude
  43. // - [L] Integration with IMDb list
  44. //
  45. // Changelog:
  46. // ----------
  47. // 2019.11.01 [1.5] Adopt Userscript Utils, some refactoring&cleanup
  48. // 2019.10.10 [1.4] Use classes instead of inline styles, some code cleanup
  49. // Optimization: permanently skip invalid entries
  50. // 2019.10.02 [1.3] Simplify code thanks to new EntryList defaults
  51. // 2019.09.30 [1.2] First public version, correct @namespace and other headers
  52. // 2019.09.27 [1.1] Changes due to EntryList (formerly TitleList) refactoring
  53. // 2019.09.21 [1.0] First version. Hide titles on click and remove useless
  54. // zooming of title cards on mouseover
  55. // 2019.09.18 [0.1] First test version, private use only
  56. //
  57. // --------------------------------------------------------------------
  58.  
  59. /* jshint laxbreak: true */
  60. /* global EL: readonly */
  61.  
  62. (function() {
  63. 'use strict';
  64.  
  65. /* BEGIN CONTEXT DEFINITION */
  66.  
  67. var timvision = EL.newContext('TIMVision');
  68.  
  69. // other variables
  70. timvision.ENTRY_CLASS = 'content-item-tile-small';
  71. timvision.CLASS_BUTTON = 'EL-TIMVision-HButton';
  72. timvision.STYLE_BUTTON = '.' + timvision.CLASS_BUTTON + ' {'
  73. + 'position: absolute;'
  74. + 'bottom: 8px;'
  75. + 'left: 8px;'
  76. + 'z-index: 1000;'
  77. + 'width: 30px;'
  78. + 'height: 30px;'
  79. + 'line-height: 30px;'
  80. + 'border: 2px solid white;'
  81. + 'border-radius: 50%;'
  82. + 'background-color: black;'
  83. + 'opacity: 0.5;'
  84. + 'text-align: center;'
  85. + 'vertical-align: middle;'
  86. + 'font-weight: bold;'
  87. + '}';
  88. timvision.CLASS_PROCESS = 'EL-TIMVision-Process';
  89. var process_selector = '.' + timvision.ENTRY_CLASS + '.' + timvision.CLASS_PROCESS;
  90. timvision.STYLE_PROCESS =
  91. process_selector + ' {opacity: 0.15; zoom: .5;} '
  92. + process_selector + ' .' + timvision.CLASS_BUTTON + ' {zoom: 2;} '
  93. + process_selector + ' .content-item-tile-title {font-size:26px;}';
  94.  
  95.  
  96. timvision.getUser = function() {
  97. var user = document.getElementsByClassName('username')[0];
  98. if (user) user = user.textContent.trim();
  99. return user;
  100. };
  101.  
  102.  
  103. timvision.getPageEntries = function() {
  104. return document.getElementsByClassName(this.ENTRY_CLASS);
  105. };
  106.  
  107.  
  108. timvision.isValidEntry = function(entry) {
  109. var tmp = entry.getElementsByTagName('a')[0];
  110. if (!tmp) return false;
  111. tmp = tmp.href;
  112. if (!tmp) return false;
  113. return (tmp.indexOf('/detail/') != -1 || tmp.indexOf('/series/') != -1)
  114. || EL.markInvalid(entry);
  115. };
  116.  
  117.  
  118. timvision.modifyEntry = function(entry) {
  119. var d = document.createElement('div');
  120. d.textContent = 'H';
  121. d.title = 'Hide/show this title';
  122. d.className = this.CLASS_BUTTON;
  123. EL.addToggleEventOnClick(d, '.' + this.ENTRY_CLASS);
  124. entry.getElementsByTagName('figure')[0].appendChild(d);
  125.  
  126. // remove useless zooming on mouseover
  127. var parent = entry.parentNode.parentNode.parentNode;
  128. if (!parent.NoMouseOver) {
  129. parent.addEventListener('mouseenter', function(e) { e.stopPropagation(); }, true);
  130. parent.NoMouseOver = true;
  131. }
  132. };
  133.  
  134.  
  135. timvision.getEntryData = function(entry) {
  136. var a = entry.querySelector('a');
  137. var id = a.href;
  138. // a.href is defined because timvision.isValidEntry() checked that
  139. id = ( id.match(/\/detail\/([0-9]+)-/) || id.match(/\/series\/([0-9]+)-/) );
  140. if (id && id.length >= 2) id = id[1];
  141.  
  142. if (!id) return null;
  143. return { 'id': id, 'name': a.title };
  144. };
  145.  
  146.  
  147. timvision.processItem = function(entry, _I_entryData, _I_processingType) {
  148. entry.classList.toggle(this.CLASS_PROCESS, true);
  149. };
  150.  
  151.  
  152. timvision.unProcessItem = function(entry, _I_entryData, _I_processingType) {
  153. entry.classList.toggle(this.CLASS_PROCESS, false);
  154. };
  155.  
  156. /* END CONTEXT DEFINITION */
  157.  
  158.  
  159.  
  160. //-------- "main" --------
  161. GM_addStyle(timvision.STYLE_BUTTON + timvision.STYLE_PROCESS);
  162. EL.startup(timvision);
  163.  
  164. })();