百度新闻链接处理

处理百度新闻链接

  1. // ==UserScript==
  2. // @name 百度新闻链接处理
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description 处理百度新闻链接
  6. // @author beifengfeng
  7. // @license MIT
  8. // @match *://*.baidu.com/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function processUrl(url) {
  16. var match = url.match(/news_(\d+)/);
  17. if (match && match[1]) {
  18. var newsId = match[1];
  19. return 'https://mbd.baidu.com/newspage/data/paysubscriptionshare?nid=news_' + newsId;
  20. }
  21. return null;
  22. }
  23.  
  24. // 创建按钮
  25. function createButton() {
  26. var button = document.createElement('button');
  27. button.textContent = '处理当前链接';
  28. button.style.position = 'fixed';
  29. button.style.top = '150px';
  30. button.style.right = '10px';
  31. button.style.zIndex = '9999';
  32. button.style.padding = '8px';
  33. button.style.backgroundColor = '#4CAF50';
  34. button.style.color = 'white';
  35. button.style.border = 'none';
  36. button.style.borderRadius = '4px';
  37. button.style.cursor = 'pointer';
  38.  
  39. button.addEventListener('click', function() {
  40. var currentUrl = window.location.href;
  41. var newUrl = processUrl(currentUrl);
  42. if (newUrl) {
  43. // 创建结果显示框
  44. var resultDiv = document.createElement('div');
  45. resultDiv.style.position = 'fixed';
  46. resultDiv.style.top = '300px';
  47. resultDiv.style.right = '10px';
  48. resultDiv.style.padding = '10px';
  49. resultDiv.style.backgroundColor = 'white';
  50. resultDiv.style.border = '1px solid #ccc';
  51. resultDiv.style.borderRadius = '4px';
  52. resultDiv.style.zIndex = '9999';
  53. resultDiv.style.display = 'flex';
  54. resultDiv.style.flexDirection = 'column';
  55. resultDiv.style.gap = '10px';
  56. var resultText = document.createElement('div');
  57. resultText.textContent = '处理后的链接:';
  58. var resultLink = document.createElement('a');
  59. resultLink.href = newUrl;
  60. resultLink.textContent = newUrl;
  61. resultLink.target = '_blank';
  62. var jumpButton = document.createElement('button');
  63. jumpButton.textContent = '立即查看';
  64. jumpButton.style.backgroundColor = '#4CAF50';
  65. jumpButton.style.color = 'white';
  66. jumpButton.style.border = 'none';
  67. jumpButton.style.borderRadius = '4px';
  68. jumpButton.style.padding = '5px 10px';
  69. jumpButton.style.cursor = 'pointer';
  70. jumpButton.addEventListener('click', function() {
  71. window.open(newUrl, '_blank');
  72. });
  73. resultDiv.appendChild(resultText);
  74. resultDiv.appendChild(resultLink);
  75. resultDiv.appendChild(jumpButton);
  76. document.body.appendChild(resultDiv);
  77. // 5秒后自动移除结果显示框
  78. setTimeout(function() {
  79. if (resultDiv && resultDiv.parentNode) {
  80. resultDiv.parentNode.removeChild(resultDiv);
  81. }
  82. }, 5000);
  83. } else {
  84. alert('未能提取到 news_id');
  85. }
  86. });
  87.  
  88. document.body.appendChild(button);
  89. }
  90.  
  91. // 页面加载完成后创建按钮
  92. if (document.readyState === 'loading') {
  93. document.addEventListener('DOMContentLoaded', createButton);
  94. } else {
  95. createButton();
  96. }
  97. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址