必应-今日热榜

必应 Bing 搜索添加今日热榜,Microsoft Rewards点击赚积分

// ==UserScript==
// @name         必应-今日热榜
// @namespace    https://greasyfork.org/zh-CN/users/1513778-chris-lu
// @version      2025.09.16.13
// @description  必应 Bing 搜索添加今日热榜,Microsoft Rewards点击赚积分
// @author       Chris Lu
// @match        *://*.bing.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=bing.com
// @require      https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js#sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==
// @license      The MIT License (MIT); http://opensource.org/licenses/MIT
// @run-at       document-end
// @grant        unsafeWindow
// @grant        GM_getResourceText
// @grant        GM_addStyle
// ==/UserScript==
GM_addStyle(`
#rebang{
//margin: 11px 0 0 var(--lgutter);
padding:0px 18px;
margin-bottom:40px;
}

#ex-search-keywords{
border:solid silver 1px;
border-radius:5px;
padding:10px;
}

.col-form-label{
line-height:30px;
margin-right:10px;
}

.form-select{
margin-right:10px;
}
.row{
  display: flex;
  flex-wrap: wrap;
  margin-bottom:10px;
}

.col-sm-3{
width:25%;
}
@media only screen and (max-width: 600px) {
.col-12{
width:100%;
}.col-6{
width:50%;
}
}
.rebang-link {
font-size:14px;
overrlow:hidden;
white-space:nowrap;
margin:3px 0px;
}
`);
this.$ = this.jQuery = jQuery.noConflict(true);

(function() {
    'use strict';
    if (window.top!== window.self) {
        // 如果不是顶层,则直接返回,不执行后续脚本
        return;
    } else{
        renderRebang();
    }
})();

function truncateText(str, maxlength) {
    if (str.length > maxlength) {
        return str.slice(0, maxlength - 1) + '…';
    }
    return str;
}

function fetchKeywordsBySource(){
    var cacheKey = `RebangChannel_${(localStorage.getItem('SelectedRebangChannel')??'微博')}`;
    if(sessionStorage.getItem(cacheKey)){
        renderKeywordsBySource(sessionStorage.getItem(cacheKey)?JSON.parse(sessionStorage.getItem(cacheKey)):null);
        console.log(`hit ${cacheKey} cache`);
    }else{

        $.ajax( {
            "url": "https://api.pearktrue.cn/api/dailyhot/?title="+(localStorage.getItem('SelectedRebangChannel')??'微博'),
            "method": "GET",
            "timeout": 0,
        }).done(function (response) {
            if(response.code==200 && response.data){
                sessionStorage.setItem(cacheKey,JSON.stringify(response.data))
                renderKeywordsBySource(response.data);
                console.log(`fetched ${cacheKey}`);
            }
        });
    }
}
function initChannels(channels, selectedChannel){
    channels?.forEach(function(element){
        var opt= new Option(element, element);
        opt.selected= element== selectedChannel;
        $('#ext-search-channels').append(opt);
    });

    $('#ext-search-channels').change(function(e){
        localStorage.setItem('SelectedRebangChannel',$(this).val());
        fetchKeywordsBySource();
    });

    $('#ext-search-link-type').change(function(e){
        fetchKeywordsBySource();
    });

    $('#ext-search-refresh').click(function(e){
        sessionStorage.removeItem(`RebangChannel_${(localStorage.getItem('SelectedRebangChannel')??'微博')}`);
        fetchKeywordsBySource();
    });

    if(localStorage.getItem('SelectedRebangChannel') == null){
        localStorage.setItem('SelectedRebangChannel',"微博");
    }

    fetchKeywordsBySource();//第一次加载
}

function renderKeywordsBySource(topics){
    $('#ex-search-keywords').empty();
    topics.forEach(function(element,index){
        if($('#ext-search-link-type').val() =='搜索')
            $('#ex-search-keywords').append(`<a target='_self' class='col-sm-3 col-12 rebang-link' title='${element.title}' href='https://www.bing.com:443/search?q=${element.title}&qs=PN&form=TSFLBL'>${index+1}.${truncateText(element.title,16)}</a>`);
        else
            $('#ex-search-keywords').append(`<a target='_blank' class='col-sm-3 col-12 rebang-link' title='${element.title}' href='${element.url??element.mobileUrl}'>${index+1}.${truncateText(element.title,16)}</a>`);
    });

    $('#ex-search-keywords').append(`<a target='_blank' class='col-12 rebang-link' href='https://rewards.bing.com/welcome?rh=3D3F7F7&ref=rafsrchae'>👉加入Microsoft Rewards点击🔥热🔥点🔥赚取积分!👈</a>`);
    $('#b_content').css('padding-top','10px');
}

function renderRebang(){
    if($('#rebang').length==0 && $('#b_content').length>0){
        $('#b_content').prepend("<div id='rebang'><div class='row'><label class='col-form-label'><strong>今日热榜: </strong></label><select id='ext-search-channels' class='form-select' title='平台'></select><label class='col-form-label'><strong>点击操作: </strong></label><select id='ext-search-link-type' class='form-select' title='操作'><option value='搜索' selected>搜索</option><option value='打开'>打开</option></select><button id='ext-search-refresh' type='button'>刷新</button></div><div class='row' id='ex-search-keywords'></div></div>");

        if(sessionStorage.getItem("RebangChannels")!==null){
            initChannels(JSON.parse(sessionStorage.getItem("RebangChannels")),localStorage.getItem('SelectedRebangChannel')??'微博');
            console.log('hit RebangChannels cache.');
        }else{
            $.ajax( {
                "url": "https://api.pearktrue.cn/api/dailyhot",
                "method": "GET",
                "timeout": 0,
            }).done(function (response) {
                if(response.code==200 && response.data && response.data.platforms){
                    sessionStorage.setItem("RebangChannels",JSON.stringify(response.data.platforms))
                    initChannels(response.data.platforms,localStorage.getItem('SelectedRebangChannel')??'微博');
                    console.log('fetched RebangChannels.');
                }
            });
        }
    }
}