Greasy Fork

Greasy Fork is available in English.

SteamCN Remember Last Search Mode

try to take over the world!

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         SteamCN Remember Last Search Mode
// @namespace    maboroshi
// @version      0.3
// @description  try to take over the world!
// @author       maboroshi
// @match        *://steamcn.com/*
// @require      https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
// @grant        GM.getValue
// @grant        GM_getValue
// @grant        GM.setValue
// @grant        GM_setValue
// ==/UserScript==
(async function () {
    'use strict';
    let ModeNamePairs = {
        'forum': '帖子',
        'user': '用户',
        'google': 'Google',
        'baidu': '百度',
    };
    for (let mode in ModeNamePairs) {
        AddEvent(mode);
    }
    let Steamcn_LastMode = await GM.getValue('Steamcn_LastMode', 'baidu');
    document.querySelector('.search-bar-form .dropdown .btn span:first-child').textContent = ModeNamePairs[Steamcn_LastMode];
    document.querySelector('.search-bar-form input[name="mod"]').value = Steamcn_LastMode;
    function AddEvent(mode) {
        document.querySelector(`a[data-mod="${mode}"]`).addEventListener('click', () => GM.setValue('Steamcn_LastMode', mode));
    }
})();