Greasy Fork

Greasy Fork is available in English.

steam史低价格显示&快速打开steamdb

在steam软件页面自动显示史低价格。在steam页面对着一个商品按ctrl+右键,即可快速打开该商品的steamdb链接,用于查看其价格曲线等。

当前为 2021-06-27 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         steam史低价格显示&快速打开steamdb
// @namespace    http://tampermonkey.net/
// @version      0.6
// @namespace    akari
// @description  在steam软件页面自动显示史低价格。在steam页面对着一个商品按ctrl+右键,即可快速打开该商品的steamdb链接,用于查看其价格曲线等。
// @author       Pikaqian
// @match        https://store.steampowered.com/*
// @icon         https://store.steampowered.com/favicon.ico
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function() {
    'use strict';
    let styleE = document.createElement('style'),button
    document.body.appendChild(styleE);
    styleE.textContent=`
    #price{
    color:#c1e0f7;
    font-size:20px;
    height:32px;
    width:40px;
    text-align:center;
    line-height:32px;
    opacity:.0;
    background: linear-gradient(to right, #3da2f1, #2561d1)
    }
    #button{
    height:16px;
    width:18px;
    border-bottom-right-radius:21px;
    border-top-right-radius:21px;
    color:#fff;
    padding:6px;
    opacity:.5;
    left:-22px;
    cursor:pointer;
    position:fixed;
    z-index:10;
    font-size:14px;
    top:38%;
    background:#fff;
    transition: 0.3s
    }`
    var match_bundle=/bundle\/\d{3,7}\//
    var match_app=/app\/\d{3,7}\//
    var match_sub=/sub\/\d{3,7}\//
    var page_url=window.location.href,img
    function openUrl(type,img){
        var page_substr=img.match(/\d{3,7}/)
        var last_id=page_substr[0]
        window.open("https://steamdb.info/"+type+"/"+last_id+"/")
        event.preventDefault()
    }
    function getA(event){
        var elemA=event.target
        for(var o=0;o<4;o++){
            if(event.target.localName=="a"){
                img=event.target.href
                break
            }
            else{
                elemA=elemA.parentNode
                if(elemA.localName=="a"){
                    img=elemA.href
                    break
                }
            }
        }
    }
    function checkImg(){
        var elemA=event.target
        if(elemA.className=="similar_recent_apps_container"||elemA.id=="recommended_block"){
            return true
        }
        else{
            for(var u=0;u<5;u++){
                elemA=elemA.parentNode
                if(elemA.className=="similar_recent_apps_container"||elemA.id=="recommended_block"){
                    return true
                }
            }
            return false
        }
    }
    function setCookie(cname,cvalue,exdays){
        var cookie_all=cname
        for(var i=0;i<20;i++){
            cookie_all=cookie_all+"1"
        }
        exdays=-1
        cookie_all=cname+"="+cvalue+"; "+exdays+";path=/"
        var d = new Date();
        d.setTime(d.getTime()+(exdays*24*60*60*1000));
        var expires = "expires="+d.toGMTString();
        document.cookie = cookie_all;
    }
    function getCookie(cname){
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for(var i=0; i<ca.length; i++) {
            var c = ca[i].trim();
            if (c.indexOf(name)==0){
                return c.substring(name.length,c.length);
            }
        }
        return "";
    }
    function getelemt(findelement){
        //——————————————————————————
        var elem_1 = document.getElementsByTagName("svg");
        for(var h=0;h<elem_1.length;h++){
            var match_result=elem_1[h].id.match(findelement)
            if(match_result!=null){
                return elem_1[h]
                break
            }
        }
        //——————————————————————————
    }
    function addRightButton () {
        var color="#fff"
        if(getCookie("low")==1){
            color="#2a6fd8"
        }
        button = document.createElementNS("http://www.w3.org/2000/svg", "svg");
        var path2 = document.createElementNS("http://www.w3.org/2000/svg", 'path');
        button.setAttribute("aria-hidden","true");
        button.setAttribute('viewbox', '0 0 24 24');
        button.setAttribute('width', '24px');
        button.setAttribute('height', '24px');
        //path2.setAttribute('d', 'M0 0 H 30 V 30 H 0 Z');
        path2.setAttribute('d','M 841.639 555.272 c 1.77544 -14.2014 3.10676 -28.626 3.10676 -43.2715 c 0 -14.6456 -1.33132 -29.0691 -3.10676 -43.2715 l 93.8658 -73.4499 c 8.43204 -6.65661 10.8737 -18.6395 5.32528 -28.4039 l -88.7616 -153.779 c -5.54734 -9.54233 -17.0872 -13.5363 -27.0726 -9.54233 l -110.509 44.6028 c -22.8566 -17.5303 -47.9317 -32.3979 -75.0032 -43.7156 L 622.841 86.8306 c -1.99749 -10.4295 -11.0957 -18.6395 -22.1904 -18.6395 l -177.523 0 c -11.0957 0 -20.1929 8.20999 -21.9683 18.6395 l -16.6431 117.61 c -27.0726 11.3167 -52.1477 25.9623 -75.0032 43.7156 l -110.508 -44.6028 c -9.98542 -3.77191 -21.5242 0 -27.0726 9.54233 l -88.7616 153.779 c -5.54734 9.54233 -3.10676 21.5242 5.32528 28.4039 l 93.6438 73.4499 c -1.77544 14.2014 -3.10676 28.626 -3.10676 43.2715 c 0 14.6456 1.33132 29.0691 3.10676 43.2715 l -93.6438 73.4499 c -8.43204 6.65661 -10.8737 18.6395 -5.32528 28.4039 l 88.7616 153.779 c 5.54734 9.54233 17.0861 13.5363 27.0726 9.54233 l 110.509 -44.6028 c 22.8566 17.5303 47.9317 32.3979 75.0032 43.7156 l 16.6431 117.61 c 1.77544 10.4295 10.8737 18.6395 21.9683 18.6395 l 177.523 0 c 11.0957 0 20.1929 -8.20999 21.9683 -18.6395 l 16.6431 -117.61 c 27.0726 -11.3167 52.1477 -25.9623 75.0032 -43.7156 l 110.508 44.6028 c 9.98542 3.77191 21.5252 0 27.0726 -9.54233 l 88.7616 -153.779 c 5.54734 -9.54233 3.10676 -21.5242 -5.32528 -28.4039 L 841.639 555.272 Z M 511.888 667.333 c -85.8769 0 -155.333 -69.4559 -155.333 -155.333 s 69.4559 -155.333 155.333 -155.333 c 85.8769 0 155.333 69.4559 155.333 155.333 S 597.765 667.333 511.888 667.333 Z')
        path2.style.transform="scale(0.016)"
        path2.setAttribute('fill', '#000');
        button.appendChild(path2);
        button.id = 'button';
        button.style.background=color
        document.body.appendChild(button);
    }
    addRightButton()
    button.addEventListener('mouseenter',()=>{
        var elem=getelemt("button")
        elem.style.transform="translateX(20px)"
    })
    button.addEventListener('mouseleave',()=>{
        var elem=getelemt("button")
        elem.style.transform="translateX(0px)"
    })
    button.addEventListener('click',()=>{
        if(getCookie("low")==""||getCookie("low")==0){
            setCookie("low","1",-1)
            document.getElementById("button").style.background="#2a6fd8"
        }
        else if(getCookie("low")==1){
            setCookie("low","0",-1)
            document.getElementById("button").style.background="#fff"
        }
    })
    if(getCookie("low")==1){
        if(page_url.match(/app\/\d{3,7}/)!=null){
            var newPrice_1=document.getElementsByClassName("game_purchase_action_bg")[0]
            var newPrice_2=document.getElementsByClassName("game_purchase_action_bg")[0].childNodes[0]
            var price
            var finalUrl=page_url.match(/app\/\d{3,7}/)[0]
            GM_xmlhttpRequest({
                method: "GET",
                url: "https://steamdb.info/"+finalUrl,
                onload: function(res) {
                    if(res.status === 200){
                        console.log('成功')
                        var p=res.responseText
                        var q=res.responseText.match("table-prices-current")
                        var a=p.split('data-cc="cn"')[p.split('data-cc="cn"').length-1]
                        var b=a.split('data-cc=')[0]
                        var r=res.responseText.substr(q.index,10)
                        var price=b.match(/\d{1,3}<\/td>/)[0].match(/\d{1,3}/)[0]
                        var price_len=price.length
                        console.log(price)
                        if(price!=undefined){
                            var oText=document.createElement("cookie_text");
                            oText.setAttribute("id","price");
                            oText.type="text";
                            var text1=document.createTextNode("¥"+price);
                            //oText.setAttribute('width',40+2*parseInt(price_len)+"px");
                            /*
                    var oo=document.getElementsByTagName("style")[0].innerText.replace(/width:40px/,"width:"+parseInt(parseInt(40)+parseInt(10*parseInt(price_len)))+"px")
                    document.getElementsByTagName("style")[0].childNodes[0].remove()
                    document.getElementsByTagName("style").appendChild(oo)
                    */
                            oText.appendChild(text1)
                            //newPrice.appendChild(oText)
                            newPrice_1.insertBefore(oText,newPrice_2);
                            oText.style.width=parseInt(parseInt(40)+parseInt(10*parseInt(price_len)))+"px"
                            oText.style.opacity="1"
                        }
                    }
                    else{
                        console.log('失败')
                        console.log(res)
                    }
                }
            })
        }
    }
    window.addEventListener('contextmenu',function (event){
        if(event.ctrlKey==true){
            if(page_url.match(match_bundle)!=null){
                openUrl("bundle",page_url)
            }
            else if(page_url.match(match_app)!=null){
                var count=0
                elemA=event.target
                if(checkImg()==true){
                    getA(event)
                    var page_substr=img.match(/\d{3,7}/)
                    var last_id=page_substr[0]
                    window.open("https://steamdb.info/app/"+last_id+"/")
                    event.preventDefault()
                }
                else{
                    openUrl("app",page_url)
                }
            }
            else if(page_url.match(match_sub)!=null){
                openUrl("sub",page_url)
            }
            else{
                var lala=event.target
                var elemA=event.target
                for(var i=0;i<10;i++){
                    if(event.target.localName=="a"){
                        img=event.target.href
                    }
                    else{
                        elemA=elemA.parentNode
                        if(elemA.localName=="a"){
                            img=elemA.href
                            break
                        }
                        else if(elemA.className=="wishlist_row"){
                            for(var m=0;m<elemA.parentNode.childNodes.length;m++){
                                if(elemA.childNodes[m].localName=="a"){
                                    img=elemA.childNodes[m].href
                                    var num=0
                                    break
                                }
                            }
                            if(num==0){
                                break
                            }
                        }
                    }
                }
                page_substr=img.match(/\d{3,7}/)
                last_id=page_substr[0]
                for(var k=0;k<img.split("/").length;k++){
                    if(img.split("/")[k]=="store.steampowered.com"){
                        var type=img.split("/")[k+1]
                        break
                    }
                }
                window.open("https://steamdb.info/"+type+"/"+last_id+"/")
                event.preventDefault()
            }
        }
    })
})();