require for ReSpeed

require for ReSpeed !

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

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/16910/106152/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. '/static/1.18.3/js/hp.js',
  31. '/js/lib/jquery.js',
  32. '/js/lib/jqueryui.js',
  33. '/js/lib/jv_care.js',
  34. '/js/lib/bootstrap.js',
  35. '/js/lib/jquery.nicescroll.min.js',
  36. '/js/html2canvas.js',
  37. '/js/dom_feedback.js',
  38. '/js/feedback.js',
  39. '/js/lib/notifier.js',
  40. '/js/forums/boutique.js'
  41. ]
  42. , styleSheets = [
  43. '/static/1.18.3/css/skin-common.css',
  44. '/static/1.18.3/css/skin-forum.css',
  45. '/static/1.18.3/css/skin-common.css',
  46. '/static/1.18.3/css/skin-hp.css'
  47. ]
  48. , locationHost = location.protocol + '//' + location.host
  49. , previousPage = location.pathname + location.search
  50. , previousScroll = 0
  51. , slowSiteWarningTimer
  52. , statsLastHover = false
  53. , statsClicksMinusHovers = []
  54. , statsLastMousedown = false
  55. , statsClicksMinusMousedowns = []
  56. , statsCancels = []
  57. , statsMousewheelsMinusHovers = []
  58. , version = localStorage.RespeedVersion
  59.  
  60.  
  61.  
  62. /***** FUNCTIONS *****/
  63.  
  64. function debug(msg) {
  65. if (!('RespeedDebug' in localStorage) && localStorage.RespeedDebug != '0') {
  66. return
  67. }
  68. console.log(typeof msg == 'string' ? ('Respeed: ' + msg) : msg)
  69. }
  70.  
  71. function cleanJvCare(node) {
  72. var spans = node.querySelectorAll('.JvCare')
  73. , attributes = 'target rel title id'.split(' ')
  74. , base16 = '0A12B34C56D78E9F'
  75. , anchor
  76. , span
  77. , attribute
  78. , attributeValue
  79. , spanParent
  80. , j
  81. , spanClasses
  82. , hiddenHref
  83. , realHref
  84.  
  85. for (var i = 0; i < spans.length; i++) {
  86. span = spans[i]
  87. anchor = document.createElement('a')
  88.  
  89. anchor.setAttribute('respeed-jvcare', '')
  90. for (j = 0; j < attributes.length; j++) {
  91. attribute = attributes[j]
  92. if (attributeValue = span.getAttribute(attribute)) {
  93. anchor.setAttribute(attribute, attributeValue)
  94. }
  95. }
  96. anchor.innerHTML = span.innerHTML
  97.  
  98. anchor.classList.add('xXx')
  99. spanClasses = span.classList
  100. hiddenHref = spanClasses[1]
  101. realHref = ''
  102. for (j = 0; j < hiddenHref.length; j += 2) {
  103. realHref += String.fromCharCode(base16.indexOf(hiddenHref[j]) * 16 + base16.indexOf(hiddenHref[j + 1]))
  104. }
  105. anchor.href = realHref
  106.  
  107. for (j = 2; j < spanClasses.length; j++) {
  108. anchor.classList.add(spanClasses[j])
  109. }
  110.  
  111. spanParent = span.parentNode
  112. spanParent.insertBefore(anchor, span)
  113. spanParent.removeChild(span)
  114. }
  115. return node
  116. }
  117.  
  118. function showSlowSiteWarning() {
  119. var element = document.createElement('div')
  120. element.id = 'slowSiteWarningContainer'
  121. element.innerHTML = '<div id="slowSiteWarning">Le site met du temps à charger…</div>'
  122. document.body.appendChild(element)
  123. }
  124.  
  125. function removeSlowSiteWarning() {
  126. var element = document.getElementById('slowSiteWarningContainer')
  127. if (element) {
  128. document.body.removeChild(element)
  129. }
  130. }
  131.  
  132. function processDelayStats() {
  133. localStorage.RespeedStatsClicksMinusHovers3 = statsClicksMinusHovers.join(' ')
  134. localStorage.RespeedStatsClicksMinusMousedowns3 = statsClicksMinusMousedowns.join(' ')
  135. localStorage.RespeedStatsCancels3 = statsCancels.join(' ')
  136. localStorage.RespeedStatsMousewheelsMinusHovers3 = statsMousewheelsMinusHovers.join(' ')
  137.  
  138. if (statsClicksMinusHovers.length >= 50) {
  139. var xhrStats = new XMLHttpRequest()
  140. , params = ''
  141.  
  142. params += 'clicks_minus_hovers=' + localStorage.RespeedStatsClicksMinusHovers3
  143. params += '&clicks_minus_mousedowns=' + localStorage.RespeedStatsClicksMinusMousedowns3
  144. params += '&cancels=' + localStorage.RespeedStatsCancels3
  145. params += '&mousewheels_minus_hovers=' + localStorage.RespeedStatsMousewheelsMinusHovers3
  146. params += '&version=' + version
  147.  
  148. xhrStats.open('POST', 'http://respeed.' + ('RespeedSendStatsToDev' in localStorage ? 'dev' : 'fr') + '/collect_delays')
  149. xhrStats.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
  150. xhrStats.send(params)
  151.  
  152. statsClicksMinusHovers = []
  153. localStorage.removeItem('RespeedStatsClicksMinusHovers2')
  154. statsClicksMinusMousedowns = []
  155. localStorage.removeItem('RespeedStatsClicksMinusMousedowns')
  156. statsCancels = []
  157. localStorage.removeItem('RespeedStatsCancels2')
  158. statsMousewheelsMinusHovers = []
  159. localStorage.removeItem('RespeedStatsMousewheelsMinusHovers3')
  160. }
  161. }
  162.  
  163. function getLinkTarget(target) {
  164. while (target && target.nodeName != 'A') {
  165. target = target.parentNode
  166. }
  167. return target
  168. }
  169.  
  170. function removeLocalStorageItems() {
  171. for (var i = 0; i < arguments.length; i++) {
  172. if (arguments[i] in localStorage) {
  173. localStorage.removeItem(arguments[i])
  174. }
  175. }
  176. }
  177.  
  178.  
  179.  
  180. /***** ON FETCH *****/
  181.  
  182. InstantClick.on('fetch', function() {
  183. /* Delay stats */
  184. statsLastHover = +new Date
  185.  
  186. // Update vars from localStorage, because if the user uses multiple tabs each Respeed
  187. // instance will overwrite on top of each other
  188. if ('RespeedStatsClicksMinusHovers2' in localStorage && localStorage.RespeedStatsClicksMinusHovers2 != statsClicksMinusHovers.join(' ')) {
  189. statsClicksMinusHovers = localStorage.RespeedStatsClicksMinusHovers2.split(' ')
  190. statsClicksMinusMousedowns = localStorage.RespeedStatsClicksMinusMousedowns.split(' ')
  191. }
  192. if ('RespeedStatsCancels2' in localStorage && localStorage.RespeedStatsCancels2 != statsCancels.join(' ')) {
  193. statsCancels = localStorage.RespeedStatsCancels2.split(' ')
  194. }
  195. })
  196.  
  197.  
  198.  
  199. /***** ON RECEIVE *****/
  200.  
  201. InstantClick.on('receive', function(url, body, title) {
  202. ;[].forEach.call(body.getElementsByTagName('script'), function (script) {
  203. var src = script.getAttribute('src')
  204. var index = scriptsBlackList.indexOf(src)
  205. if ((index > -1 || !src || !RegExp("^/(js|jwplayer)/").test(src)) && script.innerHTML.indexOf('var id_forum') == -1) {
  206. script.setAttribute('data-no-instant', '')
  207. }
  208. })
  209.  
  210. /* var jv_feedback = body.querySelector('#jv-feedback')
  211. if (jv_feedback) {
  212. body.removeChild(jv_feedback)
  213. }*/
  214.  
  215. var prospect = body.querySelector('#prospect')
  216. if (prospect) {
  217. prospect.setAttribute('hidden', '')
  218. }
  219.  
  220. var jv_footer = body.querySelector('#jv-footer')
  221. if (jv_footer) {
  222. jv_footer.innerHTML = footerHtml
  223. }
  224. clearInterval(checkFooterFilledInterval)
  225.  
  226. var image_dstats = body.querySelector('#image_dstats')
  227. if (image_dstats) {
  228. image_dstats.parentNode.removeChild(image_dstats)
  229. }
  230.  
  231. body = cleanJvCare(body)
  232.  
  233. previousScroll = scrollY
  234.  
  235. return {
  236. body: body
  237. }
  238. })
  239.  
  240.  
  241.  
  242. /***** ON CHANGE *****/
  243.  
  244. InstantClick.on('change', function(isInitialLoad) {
  245. /* Stats on mousedown */
  246. document.body.addEventListener('mousedown', function(e) {
  247. if (e.which > 1) {
  248. return
  249. }
  250. statsLastMousedown = +new Date
  251. })
  252.  
  253. /* Stats on mousewheel clicks, Firefox */
  254. document.body.addEventListener('mouseup', function(e) {
  255. if (e.button != 1 || !getLinkTarget(e.target)) {
  256. return
  257. }
  258. if (statsLastHover) { // Not there if wheelclicking on a _blank link
  259. statsMousewheelsMinusHovers.push((+new Date) - statsLastHover)
  260. statsLastHover = false
  261. }
  262. processDelayStats()
  263. })
  264.  
  265. ;[].forEach.call(document.querySelectorAll('.list-msg tr:not(.lu) .sujet-msg a'), function (non_lu) {
  266. non_lu.setAttribute('data-no-instant', '')
  267. })
  268.  
  269. var messages_precedents = document.querySelector('.btn-25-msg')
  270. if (messages_precedents) {
  271. messages_precedents.setAttribute('data-no-instant', '')
  272. }
  273.  
  274. ;[].forEach.call(document.querySelectorAll('.bloc-pre-right'), function (refreshContainer) {
  275. refreshContainer.innerHTML = '<a href="' + location.pathname + location.search + '"><span class="btn btn-actu-new-list-forum">Actualiser</span></a>'
  276. })
  277.  
  278. ;[].forEach.call(document.querySelectorAll('a'), function (anchor) {
  279. // Some SSO links trigger an action
  280. if (anchor.href.substr(0, (locationHost + '/sso/').length) == locationHost + '/sso/') {
  281. var ssoPage = anchor.href.substr((locationHost + '/sso/').length).split('.')[0]
  282. if (['logout', 'delete', 'generate_password'].indexOf(ssoPage) > -1) {
  283. anchor.setAttribute('data-no-instant', '')
  284. }
  285. }
  286. else if (anchor.href.substr(0, (locationHost + '/gta/').length) == locationHost + '/gta/') {
  287. anchor.setAttribute('data-no-instant', '')
  288. }
  289.  
  290. // Visionneuse
  291. if (anchor.href.substr(0, (locationHost + '/screenshots/').length) == locationHost + '/screenshots/') {
  292. anchor.setAttribute('data-no-instant', '')
  293. }
  294. })
  295.  
  296. if (isInitialLoad) {
  297. var prospect = document.querySelector('#prospect')
  298. if (prospect) {
  299. prospect.setAttribute('hidden', '')
  300. }
  301.  
  302. var jv_footer = document.querySelector('#jv-footer')
  303. if (jv_footer) {
  304. checkFooterFilledInterval = setInterval(function() {
  305. if (jv_footer.children.length) {
  306. jv_footer.innerHTML = footerHtml
  307. clearInterval(checkFooterFilledInterval)
  308. }
  309. }, 100)
  310. }
  311. }
  312.  
  313. // Webedia backgrounds don’t play well when switching pages with Respeed, so let’s just disable them.
  314. ;[].forEach.call(document.querySelectorAll('style[id^=wads]'), function (adStyle) {
  315. adStyle.parentNode.removeChild(adStyle)
  316. })
  317. var backgroundAdClickElement = document.querySelector('#dds_clic')
  318. if (backgroundAdClickElement) {
  319. backgroundAdClickElement.parentNode.removeChild(backgroundAdClickElement)
  320. }
  321.  
  322. // Refresh
  323. if (!isInitialLoad && previousPage == location.pathname + location.search) {
  324. if (previousScroll) {
  325. scroll(0, previousScroll)
  326. }
  327. }
  328. previousPage = location.pathname + location.search
  329.  
  330. // Clear timer about slow site
  331. clearTimeout(slowSiteWarningTimer)
  332. removeSlowSiteWarning()
  333.  
  334. /* Stats page views */
  335. localStorage.RespeedStatsPageViews++
  336.  
  337.  
  338. /* Stats delay to click */
  339. if (!isInitialLoad && statsLastHover) {
  340. statsClicksMinusHovers.push((+new Date) - statsLastHover)
  341. statsLastHover = false
  342. if (statsLastMousedown) {
  343. statsClicksMinusMousedowns.push((+new Date) - statsLastMousedown)
  344. statsLastMousedown = false
  345. }
  346. processDelayStats()
  347. }
  348. }) // end on change
  349.  
  350.  
  351.  
  352. /***** ON WAIT *****/
  353.  
  354. InstantClick.on('wait', function() {
  355. clearTimeout(slowSiteWarningTimer)
  356. slowSiteWarningTimer = setTimeout(showSlowSiteWarning, 1000)
  357.  
  358. /* Stats delay to click */
  359. statsClicksMinusHovers.push((+new Date) - statsLastHover)
  360. statsLastHover = false
  361. if (statsLastMousedown) {
  362. statsClicksMinusMousedowns.push((+new Date) - statsLastMousedown)
  363. statsLastMousedown = false
  364. }
  365. processDelayStats()
  366. })
  367.  
  368.  
  369.  
  370. /***** ON CANCEL *****/
  371.  
  372. InstantClick.on('respeedcancel', function() {
  373. /* Stats delay to click */
  374. statsCancels.push((+new Date) - statsLastHover)
  375. processDelayStats()
  376. statsLastHover = false
  377. statsLastMousedown = false
  378. })
  379.  
  380.  
  381.  
  382. /***** ON FIRST PAGE *****/
  383.  
  384. ;[].forEach.call(document.querySelectorAll('link[rel=stylesheet]'), function (styleSheet) {
  385. var index = styleSheets.indexOf(styleSheet.getAttribute('href'))
  386. if (index > -1) {
  387. styleSheets[index] = ''
  388. }
  389. })
  390.  
  391. styleSheets.forEach(function(href) {
  392. if (!href) {
  393. return
  394. }
  395. var linkElement = document.createElement('link')
  396. linkElement.rel = 'stylesheet'
  397. linkElement.href = href
  398. linkElement.setAttribute('via-respeed', '')
  399. document.head.appendChild(linkElement)
  400. })
  401.  
  402. /*var jv_feedback = document.body.querySelector('#jv-feedback')
  403. if (jv_feedback) {
  404. document.body.removeChild(jv_feedback)
  405. }
  406. else {
  407. addEventListener('load', function() {
  408. document.body.removeChild(document.body.querySelector('#jv-feedback'))
  409. })
  410. }
  411. */
  412. var prospect_interstice = document.querySelector('#prospect-interstice')
  413. if (prospect_interstice) {
  414. prospect_interstice.setAttribute('hidden', '')
  415. }
  416.  
  417.  
  418. // Stylesheet
  419. var styleElement = document.createElement('style')
  420. styleElement.setAttribute('respeed', '')
  421.  
  422. // Respeed hides the top ad banner, which will sometimes provoke a bug with the ad script,
  423. // the banner will be floating on the page, to remedy to that we simply hide the banner.
  424. styleElement.innerHTML = 'div div a img[galleryimg] { display: none; }';
  425.  
  426. // Slow site warning toast
  427. styleElement.innerHTML += '@keyframes pulse { 40%, 60% { transform: scale(1.02); } }'
  428. styleElement.innerHTML += '@-webkit-keyframes pulse { 40%, 60% { -webkit-transform: scale(1.02); } }'
  429. styleElement.innerHTML += '#slowSiteWarningContainer { pointer-events: none; position: fixed; top: 9px; width: 100%; z-index: 1051; text-align: center; }'
  430. 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; }'
  431.  
  432. // InstantClick bar
  433. styleElement.innerHTML += '#instantclick-bar { background: rgba(255,255,255,.9); }'
  434.  
  435. // Padding, as there isn’t the ad to do it anymore
  436. styleElement.innerHTML += '#content:not([style]) { padding-top: 20px; }'
  437.  
  438. document.head.appendChild(styleElement)
  439.  
  440.  
  441. // Stats
  442. // May someday be used to segment users and ask for feedback to the most active ones.
  443. if (!('RespeedStatsPageViews' in localStorage)) {
  444. localStorage.RespeedStatsPageViews = 0
  445. }
  446. if (!('RespeedStatsInstallDate' in localStorage)) {
  447. localStorage.RespeedStatsInstallDate = +new Date
  448. }
  449.  
  450.  
  451. document.querySelector('#RespeedScript').setAttribute('data-no-instant', '')
  452. // Without that, going back on the initial page through history would execute Respeed again
  453.  
  454.  
  455. /* Delete old localStorage variables */
  456. removeLocalStorageItems('RespeedStatsClicksMinusHovers', 'RespeedStatsCancels')
  457. removeLocalStorageItems('RespeedStatsClicksMinusHovers2', 'RespeedStatsClicksMinusMousedowns', 'RespeedStatsCancels2')
  458.  
  459.  
  460. /* Fetch delay stats from localStorage */
  461. if ('RespeedStatsClicksMinusHovers3' in localStorage) {
  462. statsClicksMinusHovers = localStorage.RespeedStatsClicksMinusHovers3.split(' ')
  463. }
  464. if ('RespeedStatsClicksMinusMousedowns3' in localStorage) {
  465. statsClicksMinusMousedowns = localStorage.RespeedStatsClicksMinusMousedowns3.split(' ')
  466. }
  467. if ('RespeedStatsMousewheelsMinusHovers3' in localStorage) {
  468. statsMousewheelsMinusHovers = localStorage.RespeedStatsMousewheelsMinusHovers3.split(' ')
  469. }
  470. if ('RespeedStatsCancels3' in localStorage) {
  471. statsCancels = localStorage.RespeedStatsCancels3.split(' ')
  472. }
  473. InstantClick.init()
  474.  
  475. } // end jeuxvideo.com block