require for ReSpeed

require for ReSpeed !

当前为 2016-02-07 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/16910/106145/require%20for%20ReSpeed.js

  1. if (!window.InstantClick) {
  2. /* InstantClick 3.1.0 | (C) 2014 Alexandre Dieulot | http://instantclick.io/license */
  3. // With added respeedcancel event
  4. var InstantClick=function(d,e){function w(a){var b=a.indexOf("#");return 0>b?a:a.substr(0,b)}function z(a){for(;a&&"A"!=a.nodeName;)a=a.parentNode;return a}function A(a){var b=e.protocol+"//"+e.host;if(!(b=a.target||a.hasAttribute("download")||0!=a.href.indexOf(b+"/")||-1<a.href.indexOf("#")&&w(a.href)==k)){if(J){a:{do{if(!a.hasAttribute)break;if(a.hasAttribute("data-no-instant"))break;if(a.hasAttribute("data-instant")){a=!0;break a}}while(a=a.parentNode);a=!1}a=!a}else a:{do{if(!a.hasAttribute)break;
  5. if(a.hasAttribute("data-instant"))break;if(a.hasAttribute("data-no-instant")){a=!0;break a}}while(a=a.parentNode);a=!1}b=a}return b?!1:!0}function t(a,b,c,g){for(var d=!1,e=0;e<B[a].length;e++)if("receive"==a){var f=B[a][e](b,c,g);f&&("body"in f&&(c=f.body),"title"in f&&(g=f.title),d=f)}else B[a][e](b,c,g);return d}function K(a,b,c,g){d.documentElement.replaceChild(b,d.body);if(c){history.pushState(null,null,c);b=c.indexOf("#");b=-1<b&&d.getElementById(c.substr(b+1));g=0;if(b)for(;b.offsetParent;)g+=
  6. b.offsetTop,b=b.offsetParent;scrollTo(0,g);k=w(c)}else scrollTo(0,g);d.title=S&&d.title==a?a+String.fromCharCode(160):a;L();C.done();t("change",!1);a=d.createEvent("HTMLEvents");a.initEvent("instantclick:newpage",!0,!0);dispatchEvent(a)}function M(a){G>+new Date-500||(a=z(a.target))&&A(a)&&x(a.href)}function N(a){G>+new Date-500||(a=z(a.target))&&A(a)&&(a.addEventListener("mouseout",T),H?(O=a.href,l=setTimeout(x,H)):x(a.href))}function U(a){G=+new Date;(a=z(a.target))&&A(a)&&(D?a.removeEventListener("mousedown",
  7. M):a.removeEventListener("mouseover",N),x(a.href))}function V(a){var b=z(a.target);!b||!A(b)||1<a.which||a.metaKey||a.ctrlKey||(a.preventDefault(),P(b.href))}function T(){l?(clearTimeout(l),l=!1):v&&!m&&(p.abort(),t("respeedcancel"),m=v=!1)}function W(){if(!(4>p.readyState)&&0!=p.status){q.ready=+new Date-q.start;if(p.getResponseHeader("Content-Type").match(/\/(x|ht|xht)ml/)){var a=d.implementation.createHTMLDocument("");a.documentElement.innerHTML=p.responseText.replace(/<noscript[\s\S]*?<\/noscript>/gi,"");y=a.title;
  8. u=a.body;var b=t("receive",r,u,y);b&&("body"in b&&(u=b.body),"title"in b&&(y=b.title));b=w(r);h[b]={body:u,title:y,scrollY:b in h?h[b].scrollY:0};for(var a=a.head.children,b=0,c,g=a.length-1;0<=g;g--)if(c=a[g],c.hasAttribute("data-instant-track")){c=c.getAttribute("href")||c.getAttribute("src")||c.innerHTML;for(var e=E.length-1;0<=e;e--)E[e]==c&&b++}b!=E.length&&(F=!0)}else F=!0;m&&(m=!1,P(r))}}function L(a){d.body.addEventListener("touchstart",U,!0);D?d.body.addEventListener("mousedown",M,!0):d.body.addEventListener("mouseover",
  9. N,!0);d.body.addEventListener("click",V,!0);if(!a){a=d.body.getElementsByTagName("script");var b,c,g,e;i=0;for(j=a.length;i<j;i++)b=a[i],b.hasAttribute("data-no-instant")||(c=d.createElement("script"),b.src&&(c.src=b.src),b.innerHTML&&(c.innerHTML=b.innerHTML),g=b.parentNode,e=b.nextSibling,g.removeChild(b),g.insertBefore(c,e))}}function x(a){!D&&"display"in q&&100>+new Date-(q.start+q.display)||(l&&(clearTimeout(l),l=!1),a||(a=O),v&&(a==r||m))||(v=!0,m=!1,r=a,F=u=!1,q={start:+new Date},t("fetch"),
  10. p.open("GET",a),p.send())}function P(a){"display"in q||(q.display=+new Date-q.start);l||!v?l&&r&&r!=a?e.href=a:(x(a),C.start(0,!0),t("wait"),m=!0):m?e.href=a:F?e.href=r:u?(h[k].scrollY=pageYOffset,m=v=!1,K(y,u,r)):(C.start(0,!0),t("wait"),m=!0)}var I=navigator.userAgent,S=-1<I.indexOf(" CriOS/"),Q="createTouch"in d,k,O,l,G,h={},p,r=!1,y=!1,F=!1,u=!1,q={},v=!1,m=!1,E=[],J,D,H,B={fetch:[],receive:[],wait:[],change:[],respeedcancel:[]},C=function(){function a(a,e){n=a;d.getElementById(f.id)&&d.body.removeChild(f);f.style.opacity=
  11. "1";d.getElementById(f.id)&&d.body.removeChild(f);g();e&&setTimeout(b,0);clearTimeout(l);l=setTimeout(c,500)}function b(){n=10;g()}function c(){n+=1+2*Math.random();98<=n?n=98:l=setTimeout(c,500);g()}function g(){h.style[k]="translate("+n+"%)";d.getElementById(f.id)||d.body.appendChild(f)}function e(){d.getElementById(f.id)?(clearTimeout(l),n=100,g(),f.style.opacity="0"):(a(100==n?0:n),setTimeout(e,0))}function m(){f.style.left=pageXOffset+"px";f.style.width=innerWidth+"px";f.style.top=pageYOffset+
  12. "px";var a="orientation"in window&&90==Math.abs(orientation);f.style[k]="scaleY("+innerWidth/screen[a?"height":"width"]*2+")"}var f,h,k,n,l;return{init:function(){f=d.createElement("div");f.id="instantclick";h=d.createElement("div");h.id="instantclick-bar";h.className="instantclick-bar";f.appendChild(h);var a=["Webkit","Moz","O"];k="transform";if(!(k in h.style))for(var b=0;3>b;b++)a[b]+"Transform"in h.style&&(k=a[b]+"Transform");var c="transition";if(!(c in h.style))for(b=0;3>b;b++)a[b]+"Transition"in
  13. h.style&&(c="-"+a[b].toLowerCase()+"-"+c);a=d.createElement("style");a.innerHTML="#instantclick{position:"+(Q?"absolute":"fixed")+";top:0;left:0;width:100%;pointer-events:none;z-index:2147483647;"+c+":opacity .25s .1s}.instantclick-bar{background:#29d;width:100%;margin-left:-100%;height:2px;"+c+":all .25s}";d.head.appendChild(a);Q&&(m(),addEventListener("resize",m),addEventListener("scroll",m))},start:a,done:e}}(),R="pushState"in history&&(!I.match("Android")||I.match("Chrome/"))&&"file:"!=e.protocol;
  14. return{supported:R,init:function(){if(!k)if(R){for(var a=arguments.length-1;0<=a;a--){var b=arguments[a];!0===b?J=!0:"mousedown"==b?D=!0:"number"==typeof b&&(H=b)}k=w(e.href);h[k]={body:d.body,title:d.title,scrollY:pageYOffset};for(var b=d.head.children,c,a=b.length-1;0<=a;a--)c=b[a],c.hasAttribute("data-instant-track")&&(c=c.getAttribute("href")||c.getAttribute("src")||c.innerHTML,E.push(c));p=new XMLHttpRequest;p.addEventListener("readystatechange",W);L(!0);C.init();t("change",!0);addEventListener("popstate",
  15. function(){var a=w(e.href);a!=k&&(a in h?(h[k].scrollY=pageYOffset,k=a,K(h[a].title,h[a].body,!1,h[a].scrollY)):e.href=e.href)})}else t("change",!0)},on:function(a,b){B[a].push(b)}}}(document,location);
  16. }
  17.  
  18. if (location.host == 'www.jeuxvideo.com'
  19. && !!document.querySelector('html').lang // Don’t load when we display a script/stylesheet, at least Chrome Tampermonkey does load userscripts there
  20. && location.pathname.substr(1, 12) != 'screenshots/') { // Many layout bugs on the Visionneuse, and it’s useless there
  21.  
  22.  
  23.  
  24. /***** VARIABLES *****/
  25.  
  26. var checkFooterFilledInterval
  27. , footerHtml = '<div class="liens-pied"><div class="container container-empty"><ul><li><span class="JvCare 1F424F49CB4A42CB19C045C0 a-footer">Contact</span></li><li><span class="JvCare 1F4E4A4648444FC14E19C045C0 a-footer">L\'équipe</span></li><li><span class="JvCare 1F424FC0C6C1464C45CB1945CB4E a-footer">Informations légales</span></li><li><span class="JvCare 1F424CC31945CB4E a-footer">C.G.U.</span></li><li><span class="JvCare 1F4943CCC24843CBCB43C11F a-footer">Newsletter</span></li><li><span class="JvCare 1FC04AC1CB43494A46C143C21945CB4E a-footer">Partenaires</span></li><li><span class="JvCare 1F4DC4C54E481945CB4E a-footer">RSS</span></li><li><span class="JvCare 1FC14342C1C3CB431945CB4E a-footer">Jobs</span></li></ul> <p>jeuxvideo.com, c\'est édité par L\'Odyssée Interactive, société du groupe <span class="JvCare 45CBCBC02D1F1FCCCCCC19CC4341434B464A1944C11F a-footer" rel="external" target="_blank">Webedia</span>. Fréquentation certifiée par l\'<span class="JvCare 45CBCBC02D1F1FCCCCCC194F4D4B1E4649CB43C14943CB19424F4E1F4245464444C143C21E4649CB43C14943CB1F2C232A201E4D43C3C5C4464B434F19424F4E a-footer" rel="external" target="_blank">OJD</span><br>Copyright © 1997-2014 <span rel="external" class="JvCare 45CBCBC02D1F1FCCCCCC194F4BC6C2C243431E4649CB43C14A42CB46C44319424F4E1F a-footer" target="_blank">L\'Odyssée Interactive</span> Tous droits réservés.</p></div></div>'
  28. , scriptsBlackList = [
  29. '/static/1.18.3/js/forum.js',
  30. 'https://www.google.com/recaptcha/api.js',
  31. 'http://w.estat.com/js/whap.js'
  32. 'http://mediaathay.org.uk/files/mobile-detect.min.js',
  33. 'http://mediaathay.org.uk/files/adblk4.js?ad_width=',
  34. '/static/1.18.3/js/hp.js'
  35. ]
  36. , styleSheets = [
  37. '/static/1.18.3/css/skin-common.css',
  38. '/static/1.18.3/css/skin-forum.css',
  39. '/static/1.18.3/css/skin-common.css',
  40. '/static/1.18.3/css/skin-hp.css'
  41. ]
  42. , locationHost = location.protocol + '//' + location.host
  43. , previousPage = location.pathname + location.search
  44. , previousScroll = 0
  45. , slowSiteWarningTimer
  46. , statsLastHover = false
  47. , statsClicksMinusHovers = []
  48. , statsLastMousedown = false
  49. , statsClicksMinusMousedowns = []
  50. , statsCancels = []
  51. , statsMousewheelsMinusHovers = []
  52. , version = localStorage.RespeedVersion
  53.  
  54.  
  55.  
  56. /***** FUNCTIONS *****/
  57.  
  58. function debug(msg) {
  59. if (!('RespeedDebug' in localStorage) && localStorage.RespeedDebug != '0') {
  60. return
  61. }
  62. console.log(typeof msg == 'string' ? ('Respeed: ' + msg) : msg)
  63. }
  64.  
  65. function cleanJvCare(node) {
  66. var spans = node.querySelectorAll('.JvCare')
  67. , attributes = 'target rel title id'.split(' ')
  68. , base16 = '0A12B34C56D78E9F'
  69. , anchor
  70. , span
  71. , attribute
  72. , attributeValue
  73. , spanParent
  74. , j
  75. , spanClasses
  76. , hiddenHref
  77. , realHref
  78.  
  79. for (var i = 0; i < spans.length; i++) {
  80. span = spans[i]
  81. anchor = document.createElement('a')
  82.  
  83. anchor.setAttribute('respeed-jvcare', '')
  84. for (j = 0; j < attributes.length; j++) {
  85. attribute = attributes[j]
  86. if (attributeValue = span.getAttribute(attribute)) {
  87. anchor.setAttribute(attribute, attributeValue)
  88. }
  89. }
  90. anchor.innerHTML = span.innerHTML
  91.  
  92. anchor.classList.add('xXx')
  93. spanClasses = span.classList
  94. hiddenHref = spanClasses[1]
  95. realHref = ''
  96. for (j = 0; j < hiddenHref.length; j += 2) {
  97. realHref += String.fromCharCode(base16.indexOf(hiddenHref[j]) * 16 + base16.indexOf(hiddenHref[j + 1]))
  98. }
  99. anchor.href = realHref
  100.  
  101. for (j = 2; j < spanClasses.length; j++) {
  102. anchor.classList.add(spanClasses[j])
  103. }
  104.  
  105. spanParent = span.parentNode
  106. spanParent.insertBefore(anchor, span)
  107. spanParent.removeChild(span)
  108. }
  109. return node
  110. }
  111.  
  112. function showSlowSiteWarning() {
  113. var element = document.createElement('div')
  114. element.id = 'slowSiteWarningContainer'
  115. element.innerHTML = '<div id="slowSiteWarning">Le site met du temps à charger…</div>'
  116. document.body.appendChild(element)
  117. }
  118.  
  119. function removeSlowSiteWarning() {
  120. var element = document.getElementById('slowSiteWarningContainer')
  121. if (element) {
  122. document.body.removeChild(element)
  123. }
  124. }
  125.  
  126. function processDelayStats() {
  127. localStorage.RespeedStatsClicksMinusHovers3 = statsClicksMinusHovers.join(' ')
  128. localStorage.RespeedStatsClicksMinusMousedowns3 = statsClicksMinusMousedowns.join(' ')
  129. localStorage.RespeedStatsCancels3 = statsCancels.join(' ')
  130. localStorage.RespeedStatsMousewheelsMinusHovers3 = statsMousewheelsMinusHovers.join(' ')
  131.  
  132. if (statsClicksMinusHovers.length >= 50) {
  133. var xhrStats = new XMLHttpRequest()
  134. , params = ''
  135.  
  136. params += 'clicks_minus_hovers=' + localStorage.RespeedStatsClicksMinusHovers3
  137. params += '&clicks_minus_mousedowns=' + localStorage.RespeedStatsClicksMinusMousedowns3
  138. params += '&cancels=' + localStorage.RespeedStatsCancels3
  139. params += '&mousewheels_minus_hovers=' + localStorage.RespeedStatsMousewheelsMinusHovers3
  140. params += '&version=' + version
  141.  
  142. xhrStats.open('POST', 'http://respeed.' + ('RespeedSendStatsToDev' in localStorage ? 'dev' : 'fr') + '/collect_delays')
  143. xhrStats.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
  144. xhrStats.send(params)
  145.  
  146. statsClicksMinusHovers = []
  147. localStorage.removeItem('RespeedStatsClicksMinusHovers2')
  148. statsClicksMinusMousedowns = []
  149. localStorage.removeItem('RespeedStatsClicksMinusMousedowns')
  150. statsCancels = []
  151. localStorage.removeItem('RespeedStatsCancels2')
  152. statsMousewheelsMinusHovers = []
  153. localStorage.removeItem('RespeedStatsMousewheelsMinusHovers3')
  154. }
  155. }
  156.  
  157. function getLinkTarget(target) {
  158. while (target && target.nodeName != 'A') {
  159. target = target.parentNode
  160. }
  161. return target
  162. }
  163.  
  164. function removeLocalStorageItems() {
  165. for (var i = 0; i < arguments.length; i++) {
  166. if (arguments[i] in localStorage) {
  167. localStorage.removeItem(arguments[i])
  168. }
  169. }
  170. }
  171.  
  172.  
  173.  
  174. /***** ON FETCH *****/
  175.  
  176. InstantClick.on('fetch', function() {
  177. /* Delay stats */
  178. statsLastHover = +new Date
  179.  
  180. // Update vars from localStorage, because if the user uses multiple tabs each Respeed
  181. // instance will overwrite on top of each other
  182. if ('RespeedStatsClicksMinusHovers2' in localStorage && localStorage.RespeedStatsClicksMinusHovers2 != statsClicksMinusHovers.join(' ')) {
  183. statsClicksMinusHovers = localStorage.RespeedStatsClicksMinusHovers2.split(' ')
  184. statsClicksMinusMousedowns = localStorage.RespeedStatsClicksMinusMousedowns.split(' ')
  185. }
  186. if ('RespeedStatsCancels2' in localStorage && localStorage.RespeedStatsCancels2 != statsCancels.join(' ')) {
  187. statsCancels = localStorage.RespeedStatsCancels2.split(' ')
  188. }
  189. })
  190.  
  191.  
  192.  
  193. /***** ON RECEIVE *****/
  194.  
  195. InstantClick.on('receive', function(url, body, title) {
  196. ;[].forEach.call(body.getElementsByTagName('script'), function (script) {
  197. var src = script.getAttribute('src')
  198. var index = scriptsBlackList.indexOf(src)
  199. if ((index > -1 || !src || !RegExp("^/(js|jwplayer)/").test(src)) && script.innerHTML.indexOf('var id_forum') == -1) {
  200. script.setAttribute('data-no-instant', '')
  201. }
  202. })
  203.  
  204. var jv_feedback = body.querySelector('#jv-feedback')
  205. if (jv_feedback) {
  206. body.removeChild(jv_feedback)
  207. }
  208.  
  209. var prospect = body.querySelector('#prospect')
  210. if (prospect) {
  211. prospect.setAttribute('hidden', '')
  212. }
  213.  
  214. var jv_footer = body.querySelector('#jv-footer')
  215. if (jv_footer) {
  216. jv_footer.innerHTML = footerHtml
  217. }
  218. clearInterval(checkFooterFilledInterval)
  219.  
  220. var image_dstats = body.querySelector('#image_dstats')
  221. if (image_dstats) {
  222. image_dstats.parentNode.removeChild(image_dstats)
  223. }
  224.  
  225. body = cleanJvCare(body)
  226.  
  227. previousScroll = scrollY
  228.  
  229. return {
  230. body: body
  231. }
  232. })
  233.  
  234.  
  235.  
  236. /***** ON CHANGE *****/
  237.  
  238. InstantClick.on('change', function(isInitialLoad) {
  239. /* Stats on mousedown */
  240. document.body.addEventListener('mousedown', function(e) {
  241. if (e.which > 1) {
  242. return
  243. }
  244. statsLastMousedown = +new Date
  245. })
  246.  
  247. /* Stats on mousewheel clicks, Firefox */
  248. document.body.addEventListener('mouseup', function(e) {
  249. if (e.button != 1 || !getLinkTarget(e.target)) {
  250. return
  251. }
  252. if (statsLastHover) { // Not there if wheelclicking on a _blank link
  253. statsMousewheelsMinusHovers.push((+new Date) - statsLastHover)
  254. statsLastHover = false
  255. }
  256. processDelayStats()
  257. })
  258.  
  259. ;[].forEach.call(document.querySelectorAll('.list-msg tr:not(.lu) .sujet-msg a'), function (non_lu) {
  260. non_lu.setAttribute('data-no-instant', '')
  261. })
  262.  
  263. var messages_precedents = document.querySelector('.btn-25-msg')
  264. if (messages_precedents) {
  265. messages_precedents.setAttribute('data-no-instant', '')
  266. }
  267.  
  268. ;[].forEach.call(document.querySelectorAll('.bloc-pre-right'), function (refreshContainer) {
  269. refreshContainer.innerHTML = '<a href="' + location.pathname + location.search + '"><span class="btn btn-actu-new-list-forum">Actualiser</span></a>'
  270. })
  271.  
  272. ;[].forEach.call(document.querySelectorAll('a'), function (anchor) {
  273. // Some SSO links trigger an action
  274. if (anchor.href.substr(0, (locationHost + '/sso/').length) == locationHost + '/sso/') {
  275. var ssoPage = anchor.href.substr((locationHost + '/sso/').length).split('.')[0]
  276. if (['logout', 'delete', 'generate_password'].indexOf(ssoPage) > -1) {
  277. anchor.setAttribute('data-no-instant', '')
  278. }
  279. }
  280. else if (anchor.href.substr(0, (locationHost + '/gta/').length) == locationHost + '/gta/') {
  281. anchor.setAttribute('data-no-instant', '')
  282. }
  283.  
  284. // Visionneuse
  285. if (anchor.href.substr(0, (locationHost + '/screenshots/').length) == locationHost + '/screenshots/') {
  286. anchor.setAttribute('data-no-instant', '')
  287. }
  288. })
  289.  
  290. if (isInitialLoad) {
  291. var prospect = document.querySelector('#prospect')
  292. if (prospect) {
  293. prospect.setAttribute('hidden', '')
  294. }
  295.  
  296. var jv_footer = document.querySelector('#jv-footer')
  297. if (jv_footer) {
  298. checkFooterFilledInterval = setInterval(function() {
  299. if (jv_footer.children.length) {
  300. jv_footer.innerHTML = footerHtml
  301. clearInterval(checkFooterFilledInterval)
  302. }
  303. }, 100)
  304. }
  305. }
  306.  
  307. // Webedia backgrounds don’t play well when switching pages with Respeed, so let’s just disable them.
  308. ;[].forEach.call(document.querySelectorAll('style[id^=wads]'), function (adStyle) {
  309. adStyle.parentNode.removeChild(adStyle)
  310. })
  311. var backgroundAdClickElement = document.querySelector('#dds_clic')
  312. if (backgroundAdClickElement) {
  313. backgroundAdClickElement.parentNode.removeChild(backgroundAdClickElement)
  314. }
  315.  
  316. // Refresh
  317. if (!isInitialLoad && previousPage == location.pathname + location.search) {
  318. if (previousScroll) {
  319. scroll(0, previousScroll)
  320. }
  321. }
  322. previousPage = location.pathname + location.search
  323.  
  324. // Clear timer about slow site
  325. clearTimeout(slowSiteWarningTimer)
  326. removeSlowSiteWarning()
  327.  
  328. /* Stats page views */
  329. localStorage.RespeedStatsPageViews++
  330.  
  331.  
  332. /* Stats delay to click */
  333. if (!isInitialLoad && statsLastHover) {
  334. statsClicksMinusHovers.push((+new Date) - statsLastHover)
  335. statsLastHover = false
  336. if (statsLastMousedown) {
  337. statsClicksMinusMousedowns.push((+new Date) - statsLastMousedown)
  338. statsLastMousedown = false
  339. }
  340. processDelayStats()
  341. }
  342. }) // end on change
  343.  
  344.  
  345.  
  346. /***** ON WAIT *****/
  347.  
  348. InstantClick.on('wait', function() {
  349. clearTimeout(slowSiteWarningTimer)
  350. slowSiteWarningTimer = setTimeout(showSlowSiteWarning, 1000)
  351.  
  352. /* Stats delay to click */
  353. statsClicksMinusHovers.push((+new Date) - statsLastHover)
  354. statsLastHover = false
  355. if (statsLastMousedown) {
  356. statsClicksMinusMousedowns.push((+new Date) - statsLastMousedown)
  357. statsLastMousedown = false
  358. }
  359. processDelayStats()
  360. })
  361.  
  362.  
  363.  
  364. /***** ON CANCEL *****/
  365.  
  366. InstantClick.on('respeedcancel', function() {
  367. /* Stats delay to click */
  368. statsCancels.push((+new Date) - statsLastHover)
  369. processDelayStats()
  370. statsLastHover = false
  371. statsLastMousedown = false
  372. })
  373.  
  374.  
  375.  
  376. /***** ON FIRST PAGE *****/
  377.  
  378. ;[].forEach.call(document.querySelectorAll('link[rel=stylesheet]'), function (styleSheet) {
  379. var index = styleSheets.indexOf(styleSheet.getAttribute('href'))
  380. if (index > -1) {
  381. styleSheets[index] = ''
  382. }
  383. })
  384.  
  385. styleSheets.forEach(function(href) {
  386. if (!href) {
  387. return
  388. }
  389. var linkElement = document.createElement('link')
  390. linkElement.rel = 'stylesheet'
  391. linkElement.href = href
  392. linkElement.setAttribute('via-respeed', '')
  393. document.head.appendChild(linkElement)
  394. })
  395.  
  396. var jv_feedback = document.body.querySelector('#jv-feedback')
  397. if (jv_feedback) {
  398. document.body.removeChild(jv_feedback)
  399. }
  400. else {
  401. addEventListener('load', function() {
  402. document.body.removeChild(document.body.querySelector('#jv-feedback'))
  403. })
  404. }
  405.  
  406. var prospect_interstice = document.querySelector('#prospect-interstice')
  407. if (prospect_interstice) {
  408. prospect_interstice.setAttribute('hidden', '')
  409. }
  410.  
  411.  
  412. // Stylesheet
  413. var styleElement = document.createElement('style')
  414. styleElement.setAttribute('respeed', '')
  415.  
  416. // Respeed hides the top ad banner, which will sometimes provoke a bug with the ad script,
  417. // the banner will be floating on the page, to remedy to that we simply hide the banner.
  418. styleElement.innerHTML = 'div div a img[galleryimg] { display: none; }';
  419.  
  420. // Slow site warning toast
  421. styleElement.innerHTML += '@keyframes pulse { 40%, 60% { transform: scale(1.02); } }'
  422. styleElement.innerHTML += '@-webkit-keyframes pulse { 40%, 60% { -webkit-transform: scale(1.02); } }'
  423. styleElement.innerHTML += '#slowSiteWarningContainer { pointer-events: none; position: fixed; top: 9px; width: 100%; z-index: 1051; text-align: center; }'
  424. styleElement.innerHTML += '#slowSiteWarning { pointer-events: auto; cursor: default; right: 20px; display: inline-block; border: solid 1px rgba(0,0,0,.25); background: rgba(255,255,255,.9); color: #111; font-size: 13px; font-weight: bold; padding: 3px 9px; border-radius: 3px; animation: 200ms pulse ease-in-out; -webkit-animation: 200ms pulse ease-in-out; }'
  425.  
  426. // InstantClick bar
  427. styleElement.innerHTML += '#instantclick-bar { background: rgba(255,255,255,.9); }'
  428.  
  429. // Padding, as there isn’t the ad to do it anymore
  430. styleElement.innerHTML += '#content:not([style]) { padding-top: 20px; }'
  431.  
  432. document.head.appendChild(styleElement)
  433.  
  434.  
  435. // Stats
  436. // May someday be used to segment users and ask for feedback to the most active ones.
  437. if (!('RespeedStatsPageViews' in localStorage)) {
  438. localStorage.RespeedStatsPageViews = 0
  439. }
  440. if (!('RespeedStatsInstallDate' in localStorage)) {
  441. localStorage.RespeedStatsInstallDate = +new Date
  442. }
  443.  
  444.  
  445. document.querySelector('#RespeedScript').setAttribute('data-no-instant', '')
  446. // Without that, going back on the initial page through history would execute Respeed again
  447.  
  448.  
  449. /* Delete old localStorage variables */
  450. removeLocalStorageItems('RespeedStatsClicksMinusHovers', 'RespeedStatsCancels')
  451. removeLocalStorageItems('RespeedStatsClicksMinusHovers2', 'RespeedStatsClicksMinusMousedowns', 'RespeedStatsCancels2')
  452.  
  453.  
  454. /* Fetch delay stats from localStorage */
  455. if ('RespeedStatsClicksMinusHovers3' in localStorage) {
  456. statsClicksMinusHovers = localStorage.RespeedStatsClicksMinusHovers3.split(' ')
  457. }
  458. if ('RespeedStatsClicksMinusMousedowns3' in localStorage) {
  459. statsClicksMinusMousedowns = localStorage.RespeedStatsClicksMinusMousedowns3.split(' ')
  460. }
  461. if ('RespeedStatsMousewheelsMinusHovers3' in localStorage) {
  462. statsMousewheelsMinusHovers = localStorage.RespeedStatsMousewheelsMinusHovers3.split(' ')
  463. }
  464. if ('RespeedStatsCancels3' in localStorage) {
  465. statsCancels = localStorage.RespeedStatsCancels3.split(' ')
  466. }
  467. InstantClick.init()
  468.  
  469. } // end jeuxvideo.com block