虎扑各项细节优化

手机虎扑自动跳转网页版+清空多余参数+操作细节优化

  1. // ==UserScript==
  2. // @name 虎扑各项细节优化
  3. // @version 0.3
  4. // @description 手机虎扑自动跳转网页版+清空多余参数+操作细节优化
  5. // @author 233yuzi
  6. // @match *://bbs.hupu.com/*
  7. // @match *://m.hupu.com/bbs-share/*
  8. // @icon https://w1.hoopchina.com.cn/images/pc/old/favicon.ico
  9. // @license MIT
  10. // @namespace https://greasyfork.org/users/759046
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15. console.log('启动成功')
  16. mobileToPc()
  17. openInNewWindow()
  18.  
  19. //移动端自动跳转PC
  20. function mobileToPc() {
  21. let reg = RegExp(/bbs-share/)
  22. let a = location.href
  23. if (a.match(reg)) {
  24. a = a.replace("m.", "bbs.")
  25. a = a.replace("/bbs-share", "")
  26. a = a.split('?')[0]
  27. location.href = a
  28. }
  29. }
  30. //点击链接新窗口打开
  31. function openInNewWindow() {
  32. document.addEventListener('click', (e) => {
  33. const pattern = /my.hupu.com/
  34. let target = e.target
  35. // console.log(target.innerHTML)
  36. //帖子实现新标签页打开
  37. if (target.className === 'p-title') {
  38. goto(e, target.href)
  39. }
  40. //top栏实现新标签页打开
  41. else if (target.className === 'notificatText') {
  42. if (target.innerHTML === '消息') {
  43. goto(e, 'https://my.hupu.com/message?tabKey=1')
  44. } else {
  45. goto(e, 'https://my.hupu.com/personalMessage')
  46. }
  47. }
  48. else if (pattern.test(target.href)) {
  49. goto(e, target.href)
  50. }
  51. }, true)
  52. }
  53. //跳转
  54. function goto(e, href) {
  55. e.preventDefault()
  56. e.stopPropagation()
  57. window.open(href)
  58. return false
  59. }
  60. })();