Open Discord message links in desktop client

Replace Discord message links with links using discord:// protocol so that the messages open in the desktop client.

目前为 2021-01-29 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Open Discord message links in desktop client
  3. // @namespace https://jacken.men
  4. // @version 1.1
  5. // @description Replace Discord message links with links using discord:// protocol so that the messages open in the desktop client.
  6. // @author jack1142
  7. // @license Apache-2.0; https://www.apache.org/licenses/LICENSE-2.0
  8. // @match *://*/*
  9. // @exclude /^https?://(?:(?:ptb|canary|www)\.)?discord(?:app)?\.com/
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. // Copyright 2021 Jakub Kuczys (https://github.com/jack1142)
  14. //
  15. // Licensed under the Apache License, Version 2.0 (the "License");
  16. // you may not use this file except in compliance with the License.
  17. // You may obtain a copy of the License at
  18. //
  19. // https://www.apache.org/licenses/LICENSE-2.0
  20. //
  21. // Unless required by applicable law or agreed to in writing, software
  22. // distributed under the License is distributed on an "AS IS" BASIS,
  23. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  24. // See the License for the specific language governing permissions and
  25. // limitations under the License.
  26.  
  27. (function() {
  28. 'use strict';
  29.  
  30. const LINK_REGEX = /^https?:\/\/(?:(?:ptb|canary|www)\.)?discord(?:app)?\.com\/channels\/((?:\d{15,21}|@me)\/\d{15,21}\/\d{15,21})\/?$/i;
  31.  
  32. const links = document.querySelectorAll("a[href]");
  33.  
  34. for (let link of links) {
  35. const match = link.href.match(LINK_REGEX);
  36. if (match === null) {
  37. continue;
  38. }
  39. link.href = `discord://discord.com/channels/${match[1]}`;
  40. }
  41. })();