Open Douban Link Directly

Do not remind me of leaving Douban please, I know that...

  1. // ==UserScript==
  2. // @name Open Douban Link Directly
  3. // @namespace https://www.douban.com/people/MoNoMilky/
  4. // @version 0.2
  5. // @description Do not remind me of leaving Douban please, I know that...
  6. // @match https://*.douban.com/*
  7. // @author Bambooom
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. function contains(selector, text) {
  15. var elements = document.querySelectorAll(selector);
  16. return Array.prototype.filter.call(elements, function(element) {
  17. return RegExp(text).test(element.textContent);
  18. });
  19. }
  20.  
  21. var links = contains('a', /^https:\/\/douc\.cc/);
  22. for (let link of links) {
  23. link.onclick = function(event) {
  24. var url = event.target.title;
  25. if (url) { // only with title, the shorten url may need to open directly
  26. event.preventDefault();
  27. window.open(url);
  28. }
  29. }
  30. }
  31.  
  32. if (location.pathname === '/link2/') {
  33. var url = (new URL(location)).searchParams.get('url');
  34. window.location = url;
  35. }
  36. })();