Last active
January 29, 2021 00:30
-
-
Save Jackenmen/2246d6f27b35391f01f6615e62442340 to your computer and use it in GitHub Desktop.
Replace Discord message links with links using discord:// protocol so that the messages open in the desktop client.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Open Discord message links in desktop client | |
// @namespace https://jacken.men | |
// @version 1.1 | |
// @description Replace Discord message links with links using discord:// protocol so that the messages open in the desktop client. | |
// @author jack1142 | |
// @license Apache-2.0; https://www.apache.org/licenses/LICENSE-2.0 | |
// @match *://*/* | |
// @exclude /^https?://(?:(?:ptb|canary|www)\.)?discord(?:app)?\.com/ | |
// @grant none | |
// ==/UserScript== | |
// Copyright 2021 Jakub Kuczys (https://github.com/jack1142) | |
// | |
// Licensed under the Apache License, Version 2.0 (the "License"); | |
// you may not use this file except in compliance with the License. | |
// You may obtain a copy of the License at | |
// | |
// https://www.apache.org/licenses/LICENSE-2.0 | |
// | |
// Unless required by applicable law or agreed to in writing, software | |
// distributed under the License is distributed on an "AS IS" BASIS, | |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
// See the License for the specific language governing permissions and | |
// limitations under the License. | |
(function() { | |
'use strict'; | |
const LINK_REGEX = /^https?:\/\/(?:(?:ptb|canary|www)\.)?discord(?:app)?\.com\/channels\/((?:\d{15,21}|@me)\/\d{15,21}\/\d{15,21})\/?$/i; | |
const links = document.querySelectorAll("a[href]"); | |
for (let link of links) { | |
const match = link.href.match(LINK_REGEX); | |
if (match === null) { | |
continue; | |
} | |
link.href = `discord://discord.com/channels/${match[1]}`; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment