UserScript demo for Baidu main page.

this is the description

目前為 2023-09-15 提交的版本,檢視 最新版本

// ==UserScript==
// @name UserScript demo for Baidu main page.
// @namespace http://tampermonkey.net/
// @version 0.1
// @description  this is the description
// @match *www.baidu.com*
// @grant GM_addStyle
// @license MIT
// ==/UserScript==



function main() {
    // add button to headNav
    let headNav = document.querySelector("#s-top-left");
    let myButton = document.createElement("Button");
    myButton.innerText = 'news';
    myButton.addEventListener('click', () => {
        // get all the news on the right side
        let newsList = document.querySelectorAll(".s-news-rank-content > li > a > span.title-content-title");
        for (const node of newsList) {
            console.log(node.innerText);
        }

    })
    headNav.appendChild(myButton);

}

(function () {
    'use strict';
    main();
})()