Sonkwo_Steam_Search

半自动添加游戏链接

目前为 2021-08-26 提交的版本。查看 最新版本

// ==UserScript==
// @name         Sonkwo_Steam_Search
// @name:zh-CN   杉果Steam快捷搜索
// @namespace    https://blog.chrxw.com/
// @version      1.0
// @description  半自动添加游戏链接
// @description:zh-CN  半自动添加游戏链接
// @author       Chr_
// @license      AGPL-3.0
// @connect      steampowered.com
// @include      /https://www.sonkwo.com\/sku\/\d+$/
// @include      /https://www.sonkwo.hk\/sku\/\d+$/
// @require      https://gf.qytechs.cn/scripts/431430-search-steam-store/code/Search_Steam_Store.js
// @grant        GM_xmlhttpRequest
// @grant        GM_addStyle
// ==/UserScript==

const GObjs = {};

(() => {
    'use strict';
    const t = setInterval(() => {
        if (document.querySelectorAll('h3.typical-name-1').length > 0) {
            clearInterval(t);
            init();
        }
    }, 500);
})();

function init() {
    const title = document.querySelector('h5.typical-name-2') || document.querySelector('h3.typical-name-1');
    const keyword = title.textContent;

    const btnSearch = document.createElement('button');
    btnSearch.className = 'btnSearch';
    btnSearch.textContent = '🔎';
    btnSearch.addEventListener('mouseover', () => { btnSearch.textContent = '🔎 搜索Steam'; });
    btnSearch.addEventListener('mouseout', () => { btnSearch.textContent = '🔎'; });
    btnSearch.addEventListener('click', () => { showResult(keyword); });
    title.appendChild(btnSearch);

    const divResult = document.createElement('div');
    divResult.className = 'divResult';
    divResult.style.display = 'none';
    title.appendChild(divResult);

    Object.assign(GObjs, { divResult });
}

function showResult(keyword) {
    const { divResult } = GObjs;
    searchStore(keyword, 'CN')
        .then((result) => {
            if (result.length === 0) {
                return;
            }
            divResult.style.display = '';
            divResult.innerHTML = '';
            result.forEach(({ appID, isBundle, appName, appPrice, appUrl, appImg }) => {
                const btnRst = document.createElement('button');
                btnRst.title = `${isBundle ? "bundle" : "app"}/${appID}`;
                btnRst.addEventListener('click', () => { window.open(appUrl); });

                const btnName = document.createElement('p');
                btnName.textContent = `${appName}【${appPrice}】`
                btnRst.appendChild(btnName);

                const btnImg = new Image();
                btnImg.src = appImg;

                btnRst.appendChild(btnImg);
                divResult.appendChild(btnRst);
            });
        })
        .catch((reason) => {
            alert(reason);
        });
}

//CSS表
GM_addStyle(`
.divResult {
    top: -180px;
    position: relative;
    display: flex;
}
.divResult > button:not(:last-child) {
  margin-right: 5px;
}
.divResult > button > p {
  display: inline;
  margin-left: 6px;
}
.divResult > button > img {
  zoom: 1.5;
  margin-top: 2px;
}
.btnSearch {
  padding: 0 5px;
  margin-left: 5px;
}

`);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址