UserScript demo for Baidu main page.

this is the description

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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();
})()