您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Adds GG.Deals and PCGamingWiki links to GOG game pages with icons + asterisk that performs a clean PCGW search (simplified title without subtitles or editions)
// ==UserScript== // @name GOG Game Page - GG.Deals & PCGW with Icons + Clean Asterisk Search // @namespace http://tampermonkey.net/ // @version 1.4 // @description Adds GG.Deals and PCGamingWiki links to GOG game pages with icons + asterisk that performs a clean PCGW search (simplified title without subtitles or editions) // @author - // @match https://www.gog.com/*/game/* // @grant none // @license MIT // @run-at document-idle // ==/UserScript== (function () { 'use strict'; const GGDEALSIconUrl = 'hgg.deals/favicon-32x32.png'; const pcgwIconUrl = 'https://static.pcgamingwiki.com/favicons/pcgamingwiki.png'; // To override certain titles to PCGW const manualSlugOverrides = { 'the witcher 3: wild hunt - game of the year edition': 'The_Witcher_3:_Wild_Hunt', 'dark souls iii - game of the year edition': 'Dark_Souls_III', 'the elder scrolls v skyrim special edition': 'The_Elder_Scrolls_V:_Skyrim_Special_Edition', }; const slugify = str => str.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').replace(/-+/g, '-'); function toPCGWTitle(str) { return str .trim() .split(/\s+/) .map(word => word.charAt(0).toUpperCase() + word.slice(1)) .join('_'); } // Simplify the title for searching * (without subtitles, editions, etc.) function simplifyTitleForSearch(title) { let simple = title.split(/[:\-–(]/)[0]; // coupe à :, -, –, ( simple = simple.replace(/Edition|Game\s*of\s*the\s*Year|GOTY|Remastered|Definitive|Complete|HD|Deluxe/gi, ''); return simple.trim(); } function waitForTitle(maxMs = 5000) { return new Promise((resolve, reject) => { const interval = 100; let elapsed = 0; const check = () => { const titleEl = document.querySelector('h1.game-title, .productcard-basics__title'); if (titleEl) resolve(titleEl); else { elapsed += interval; if (elapsed >= maxMs) reject('Titre introuvable'); else setTimeout(check, interval); } }; check(); }); } function makeLinkWithIcon(url, label, iconUrl) { const a = document.createElement('a'); a.href = url; a.target = '_blank'; a.style.marginRight = '12px'; a.style.display = 'inline-flex'; a.style.alignItems = 'center'; a.style.textDecoration = 'none'; a.style.color = '#0a84ff'; a.style.fontWeight = '500'; const img = document.createElement('img'); img.src = iconUrl; img.alt = ''; img.style.width = '16px'; img.style.height = '16px'; img.style.marginRight = '6px'; a.appendChild(img); a.appendChild(document.createTextNode(label)); a.addEventListener('mouseenter', () => (a.style.textDecoration = 'underline')); a.addEventListener('mouseleave', () => (a.style.textDecoration = 'none')); return a; } waitForTitle() .then(titleEl => { const title = titleEl.textContent.trim(); const titleLower = title.toLowerCase(); const slugFull = slugify(title); const pcgwSlug = manualSlugOverrides[titleLower] || toPCGWTitle(title); const GGDEALSUrl = `https://gg.deals/game/${slugFull}/`; const pcgwUrl = `https://www.pcgamingwiki.com/wiki/${pcgwSlug}`; // Use of simplified title for search * const simpleTitle = simplifyTitleForSearch(title); const pcgwSearchUrl = `https://www.pcgamingwiki.com/wiki/Special:Search?search=${encodeURIComponent(simpleTitle)}`; const container = document.createElement('div'); container.style.marginTop = '8px'; container.style.fontSize = '14px'; container.style.lineHeight = '1.4em'; const GGDEALSLink = makeLinkWithIcon(GGDEALSUrl, 'GG.deals', GGDEALSIconUrl); const pcgwLink = makeLinkWithIcon(pcgwUrl, 'PCGamingWiki', pcgwIconUrl); const asteriskWrapper = document.createElement('span'); asteriskWrapper.style.marginLeft = '6px'; const asterisk = document.createElement('a'); asterisk.href = pcgwSearchUrl; asterisk.textContent = '*'; asterisk.title = 'Recherche approximative sur PCGamingWiki'; asterisk.target = '_blank'; asterisk.style.color = '#0a84ff'; asterisk.style.fontWeight = '700'; asterisk.style.textDecoration = 'none'; asterisk.style.cursor = 'pointer'; asterisk.addEventListener('mouseenter', () => (asterisk.style.textDecoration = 'underline')); asterisk.addEventListener('mouseleave', () => (asterisk.style.textDecoration = 'none')); asteriskWrapper.appendChild(asterisk); container.appendChild(GGDEALSLink); container.appendChild(pcgwLink); container.appendChild(asteriskWrapper); titleEl.parentNode.insertBefore(container, titleEl.nextSibling); }) .catch(err => { console.warn('Error script GGDEALS/PCGW :', err); }); })();