|
|
本帖最后由 147406 于 2026-11-26 14:18 编辑
没蓝绿插件用太难受了,这个只是临时修复脚本,坛子的sync因为换了个域名会有跨域问题读不到数据,所以直接从本地读出来就可以临时用
去油猴添加新脚本就好
- // ==UserScript==
- // @name Keylol 蓝绿标记修复
- // @namespace https://keylol.com/
- // @description 同步 Steam 已购/愿望单,恢复 Keylol 绿/蓝底标记(整合 Steam Info)
- // @version 1.2.1
- // @match https://keylol.com/*
- // @match https://steam-tooltip-lite.depar.me/sync
- // @grant GM_getValue
- // @grant GM_setValue
- // @grant GM_xmlhttpRequest
- // @connect steamcommunity.com
- // @connect store.steampowered.com
- // @run-at document-idle
- // ==/UserScript==
- (function () {
- 'use strict';
- var KEY_OWN = 'keylol_fix_own';
- var KEY_WISH = 'keylol_fix_wish';
- var SYNC_HOST = 'steam-tooltip-lite.depar.me';
- function exec(fn) {
- var s = document.createElement('script');
- s.textContent = fn;
- document.body.appendChild(s);
- document.body.removeChild(s);
- }
- function load(url, id) {
- GM_xmlhttpRequest({
- method: 'GET',
- url: url,
- onload: function (r) {
- var data = JSON.stringify(r.responseText).replace(/<\/script/gi, '<\\/script');
- exec('proc_' + id + '(' + data + ')');
- }
- });
- }
- function saveFromStorage(own, wish) {
- GM_setValue(KEY_OWN, own || '[]');
- GM_setValue(KEY_WISH, wish || '[]');
- console.log('[Keylol蓝绿修复] 已保存:own=' + JSON.parse(own || '[]').length +
- ' wish=' + JSON.parse(wish || '[]').length);
- }
- if (location.host === SYNC_HOST) {
- exec('setScriptVersion(' + JSON.stringify(GM_info.script.version) + ')');
- load('https://steamcommunity.com/my/games?tab=all', 'own');
- load('https://store.steampowered.com/dynamicstore/userdata/?_=' +
- Math.floor(Math.random() * 100000), 'userdata');
- var initialLast = localStorage.getItem('last') || '';
- var tries = 0;
- var timer = setInterval(function () {
- tries++;
- var last = localStorage.getItem('last') || '';
- var own = localStorage.getItem('own');
- var wish = localStorage.getItem('wish');
- if (own && (last !== initialLast || tries > 180)) {
- saveFromStorage(own, wish);
- clearInterval(timer);
- } else if (tries > 180) {
- clearInterval(timer);
- console.warn('[Keylol蓝绿修复] 同步未完成');
- }
- }, 500);
- return;
- }
- if (!document.querySelector('script[src*="steam_info.js"]')) {
- var info = document.createElement('script');
- info.src = 'https://' + SYNC_HOST + '/steam_info.js';
- document.body.appendChild(info);
- }
- var STYLE_ID = 'keylol-bluegreen-fix-style';
- function injectStyle() {
- if (document.getElementById(STYLE_ID)) return;
- var s = document.createElement('style');
- s.id = STYLE_ID;
- s.textContent =
- '.steam-info-own,.steam-info-wish{color:#fff!important}' +
- '.steam-info-own{background:#5C8A00!important}' +
- '.steam-info-wish{background:#007399!important}';
- (document.head || document.documentElement).appendChild(s);
- }
- var pending = null;
- function apply() {
- var own, wish;
- try {
- own = JSON.parse(GM_getValue(KEY_OWN, '[]') || '[]');
- wish = JSON.parse(GM_getValue(KEY_WISH, '[]') || '[]');
- } catch (e) {
- return;
- }
- if (!own.length && !wish.length) return;
- injectStyle();
- var links = document.querySelectorAll(
- 'a[href*="store.steampowered.com/app/"],' +
- 'a[href*="store.steampowered.com/sub/"],' +
- 'a[href*="store.steampowered.com/bundle/"],' +
- '.steam-info-trigger-text[data-href]'
- );
- var green = 0, blue = 0;
- [].forEach.call(links, function (a) {
- if (a.getAttribute('data-keylol-fix-done')) return;
- var url = a.getAttribute('data-href') || a.href || '';
- var m = String(url).match(/\/(?:app|sub|bundle)\/(\d+)/);
- if (!m) return;
- var id = parseInt(m[1], 10);
- var cls = own.indexOf(id) !== -1 ? 'steam-info-own'
- : wish.indexOf(id) !== -1 ? 'steam-info-wish' : null;
- a.setAttribute('data-keylol-fix-done', '1');
- if (!cls) return;
- a.style.color = '';
- a.style.fontWeight = '';
- a.style.backgroundColor = '';
- if (a.classList.contains('steam-info-trigger-text')) a.classList.add('steam-info-link');
- a.classList.add(cls);
- var tag = cls === 'steam-info-own' ? '已拥有' : '愿望单';
- var t = a.getAttribute('title') || '';
- if (t.indexOf('[' + tag + ']') === -1) a.setAttribute('title', t + ' [' + tag + ']');
- if (cls === 'steam-info-own') green++; else blue++;
- });
- if (green || blue) console.log('[Keylol蓝绿修复] 绿=' + green + ' 蓝=' + blue);
- }
- function schedule() {
- if (pending) clearTimeout(pending);
- pending = setTimeout(apply, 150);
- }
- apply();
- if (typeof MutationObserver !== 'undefined') {
- new MutationObserver(schedule).observe(document.body, { childList: true, subtree: true });
- }
- })();
复制代码
|
1、转载或引用本网站内容,必须注明本文网址:https://keylol.com/t1056407-1-1。如发文者注明禁止转载,则请勿转载
2、对于不当转载或引用本网站内容而引起的民事纷争、行政处理或其他损失,本网站不承担责任
3、对不遵守本声明或其他违法、恶意使用本网站内容者,本网站保留追究其法律责任的权利
4、所有帖子仅代表作者本人意见,不代表本社区立场
|