|
javascript: (function() { |
|
'use strict'; |
|
var settings = {"target_hrefs": ["://discord.com/channels"], "exclude_str": ["@me"]}; |
|
var data = {"detectedLinks": []}; |
|
|
|
function open_widget(id) { |
|
if (!id) id = prompt("Discord guild ID?") || false; |
|
if (id === false) { |
|
console.error("Error: Discord guild ID is not provided!"); |
|
return 1; |
|
} |
|
if (isNaN(parseInt(id))) { |
|
console.error("Error: Discord guild ID should be integer!"); |
|
return 1; |
|
} |
|
if ((id < 0) || (id > 9223372036854775807)) { |
|
console.error("Error: Discord guild ID should be between 0 and 9223372036854775807!"); |
|
return 1; |
|
} |
|
window.open("https://discord.com/widget?id="+id+"&theme=dark"); |
|
return 0; |
|
} |
|
|
|
/* if (settings['target_hrefs'].filter(href => href.startsWith(window.location.href)).length === 0) { */ |
|
if (!window.location.href.includes(settings['target_hrefs'][0])) { |
|
open_widget(); |
|
return 1; |
|
} |
|
console.debug(settings['target_hrefs'].filter(href => href.startsWith(window.location.href))); |
|
console.debug("Seems to logged in..."); |
|
if (window.location.href.includes(settings['exclude_str'][0])) { |
|
console.warn("But this for guilds only."); |
|
open_widget(); |
|
return 1; |
|
} |
|
var hrefs = document.querySelectorAll('[href]'); |
|
for (var i = 0; i < hrefs.length; ++i) { |
|
var item = hrefs[i].getAttribute("href"); |
|
if (item === null) continue; |
|
if (!item.includes("channels") || item.includes(settings['exclude_str'][0])) continue; |
|
data['detectedLinks'].push(item); |
|
} |
|
if (data['detectedLinks'].length === 0) { |
|
console.warn("Error: No channels!"); |
|
open_widget(href_splitted[1]); |
|
return 1; |
|
} |
|
console.debug("detectedLinks:", data['detectedLinks']); |
|
var href_splitted = data['detectedLinks'][Math.round(Math.random() * data['detectedLinks'].length)].split('/'); |
|
if (href_splitted[0] == "") href_splitted.shift(); |
|
if (href_splitted.length < 3) { |
|
console.error("Error: Low href lenght!"); |
|
return 1; |
|
} |
|
console.debug("href_splitted:", href_splitted); |
|
open_widget(window.location.href.split('/')[4]); |
|
return 0; |
|
})(); |