// ==UserScript== // @name ResetEra Live Thread // @namespace http://madjoki.com // @version 4.0.15 // @description Update threads without refreshing // @author Madjoki // @match https://metacouncil.com/threads/* // @match https://www.resetera.com/threads/* // @match https://bbs.io-tech.fi/threads/* // @require https://cdnjs.cloudflare.com/ajax/libs/favico.js/0.3.10/favico.min.js // @grant none // @downloadURL https://update.greasyfork.icu/scripts/34580/ResetEra%20Live%20Thread.user.js // @updateURL https://update.greasyfork.icu/scripts/34580/ResetEra%20Live%20Thread.meta.js // ==/UserScript== (function () { 'use strict'; let favicon; // This is to disable scrolldown behaviour when XenForo insert "new messages" box. const original = XF.Message.insertMessages; XF.Message.insertMessages = function (dataHtml, $container, ascending, onInsert) { console.log(dataHtml, $container, ascending, onInsert); if (dataHtml.content.indexOf('js-newMessagesIndicator') > -1) return; original(dataHtml, $container, ascending, onInsert); } var favIconUpdate = function (count) { favicon.badge(count); favicon.badge(count); } if (window.location.host === 'www.resetera.com') { // Chrome Fix //let icon = $('link[rel*=icon]').first().clone(); //$('link[rel*=icon]').remove(); //$('head').append(icon); favicon = new Favico({ animation: 'none', fontFamily: 'FontAwesome', fontStyle: 'normal' }); } else { favicon = new Favico({ animation: 'none', fontFamily: 'FontAwesome', fontStyle: 'normal' }); } favIconUpdate(); var timeoptions = [ { name: "5s", value: 5, }, { name: "10s", value: 10, }, { name: "15s", value: 15, }, { name: "30s", value: 30, }, { name: "1m", value: 60, }, { name: "2m", value: 120, }, ]; let defaults = { timer: 5, enabledByDefault: false, }; let threadID = $('html').data('content-key'); let userSettings = {} let threadSettings = {} let recentErrors = 0; let countNewMessages = 0; let updating = false; let enabled = false; let paused = false; let currentTimer = 120; let hasFocus = true; // Read Global Settings let settingsJson = localStorage.getItem("livethreadSettings"); if (settingsJson !== null) userSettings = JSON.parse(settingsJson) || {}; // Read Thread Settings let threadJson = localStorage.getItem("livethread_" + threadID); if (threadJson !== null) threadSettings = JSON.parse(threadJson) || {}; let currentSettings = {} function updateSettings() { currentSettings = { ...defaults, ...userSettings, ...threadSettings } if (!("enabled" in currentSettings)) currentSettings.enabled = currentSettings.enabledByDefault; if (!currentSettings.timer || currentSettings.timer < 0) currentSettings.enabled = false; enabled = currentSettings.enabled; paused = !enabled; } updateSettings(); currentTimer = currentSettings.timer; function getPages(dom) { return { current: parseInt(dom.find('li.pageNav-page--current').first().text(), 10) || 0, next: parseInt(dom.find('.pageNav-page.pageNav-page--later').first().text()) || parseInt(dom.find('.pageNav-page').last().text()) || 0, last: parseInt(dom.find('.pageNav-page').last().text()) || 0 }; } function updateFavIcon() { if (countNewMessages > 0) { favIconUpdate(countNewMessages); } else if (currentSettings.enabled && !paused) { favIconUpdate(''); } else { favIconUpdate(0); } } function addoptions(el, values) { $(el).find("option").remove(); $(values).each(function (i, o) { $(el).append($("