UserScript demo for Baidu main page.

this is the description

  1. // ==UserScript==
  2. // @name UserScript demo for Baidu main page.
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description this is the description
  6. // @match *www.baidu.com*
  7. // @grant GM_addStyle
  8. // @license MIT
  9. // ==/UserScript==
  10.  
  11.  
  12.  
  13. function main() {
  14. // add button to headNav
  15. let headNav = document.querySelector("#s-top-left");
  16. let myButton = document.createElement("Button");
  17. myButton.innerText = 'news';
  18. myButton.addEventListener('click', () => {
  19. // get all the news on the right side
  20. let newsList = document.querySelectorAll(".s-news-rank-content > li > a > span.title-content-title");
  21. for (const node of newsList) {
  22. console.log(node.innerText);
  23. }
  24.  
  25. })
  26. headNav.appendChild(myButton);
  27.  
  28. }
  29.  
  30. (function () {
  31. 'use strict';
  32. main();
  33. })()