自动搜索微软积分-国内外通用

自用微软积分搜索脚本,国际版与国内版通用

目前為 2023-03-14 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         自动搜索微软积分-国内外通用
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  自用微软积分搜索脚本,国际版与国内版通用
// @author       青鸟丹心
// @match        https://www.bing.com/*
// @grant        none
// ==/UserScript==

const searchUrl = 'https://www.bing.com/search';
const isDesktop = window.matchMedia("(min-width: 768px)").matches; // 检查是否为电脑端

// Check if the current URL is bing.com
if (window.location.hostname === 'www.bing.com') {
    // If it is, execute the random search every 2000 milliseconds (2 seconds)
    const loopCount = isDesktop ? 50 : 30; // 根据设备类型设置循环次数
    let count = 0; // 计数器,用于记录循环次数
    const intervalId = setInterval(function() {
        // Generate a random search query
        const search = generateRandomSearch();

        // Enter the search query into the Bing search bar
        document.getElementById("sb_form_q").value = search;
        // Submit the search
        document.getElementById("sb_form").submit();

        // Increment the counter and check if we've reached the loop count
        count++;
        if (count === loopCount) {
            clearInterval(intervalId); // 停止循环
        }
    }, 2000);
}

function generateRandomSearch() {
    let search = '';
    // Generate a random string of 5 characters
    for (let i = 0; i < 5; i++) {
        // Generate a random number between 0 and 1
        const r = Math.random();
        // If the number is less than 0.5, add a random letter
        if (r < 0.5) {
            search += String.fromCharCode(Math.floor(Math.random() * 26) + 65);
        }
        // Otherwise, add a random number (0-9) to the search string
        else {
            search += Math.floor(Math.random() * 10);
        }
    }
    return search;
}