2019-06-29 19:54:25 +02:00
|
|
|
var browser: Browser = browser || chrome;
|
2018-09-16 12:27:42 +02:00
|
|
|
|
|
|
|
var hostname = typeof (location) != 'undefined' ? location.hostname : '';
|
|
|
|
if (hostname.startsWith('www.')) {
|
|
|
|
hostname = hostname.substring(4);
|
|
|
|
}
|
2019-10-26 12:37:42 +02:00
|
|
|
if (hostname == 'mobile.twitter.com') hostname = 'twitter.com';
|
2018-09-16 12:27:42 +02:00
|
|
|
if (hostname.endsWith('.reddit.com')) hostname = 'reddit.com';
|
2019-02-25 23:44:34 +01:00
|
|
|
if (hostname.endsWith('.facebook.com')) hostname = 'facebook.com';
|
2019-03-03 21:27:45 +01:00
|
|
|
if (hostname.endsWith('.youtube.com')) hostname = 'youtube.com';
|
2018-09-16 12:27:42 +02:00
|
|
|
|
2019-06-29 19:54:25 +02:00
|
|
|
var myself: string = null;
|
2019-10-06 13:04:11 +02:00
|
|
|
var isSocialNetwork: boolean = null;
|
2018-11-16 21:51:31 +01:00
|
|
|
|
2018-12-16 17:36:19 +01:00
|
|
|
function fixupSiteStyles() {
|
2019-06-29 19:47:05 +02:00
|
|
|
if (hostname == 'facebook.com') {
|
|
|
|
let m = document.querySelector("[id^='profile_pic_header_']")
|
|
|
|
if (m) myself = 'facebook.com/' + captureRegex(m.id, /header_(\d+)/);
|
|
|
|
} else if (hostname == 'medium.com') {
|
|
|
|
addStyleSheet(`
|
|
|
|
a.show-thread-link, a.ThreadedConversation-moreRepliesLink {
|
|
|
|
color: inherit !important;
|
|
|
|
}
|
|
|
|
.fullname,
|
|
|
|
.stream-item a:hover .fullname,
|
|
|
|
.stream-item a:active .fullname
|
|
|
|
{color:inherit;}
|
|
|
|
`);
|
|
|
|
} else if (domainIs(hostname, 'tumblr.com')) {
|
|
|
|
addStyleSheet(`
|
2019-07-17 23:35:00 +02:00
|
|
|
.assigned-label-transphobic { outline: 2px solid var(--ShinigamiEyesTransphobic) !important; }
|
|
|
|
.assigned-label-t-friendly { outline: 1px solid var(--ShinigamiEyesTFriendly) !important; }
|
2019-06-29 19:47:05 +02:00
|
|
|
`);
|
2019-10-06 11:23:23 +02:00
|
|
|
} else if (hostname == 'rationalwiki.org' || domainIs(hostname, 'wikipedia.org')) {
|
2019-06-29 19:47:05 +02:00
|
|
|
addStyleSheet(`
|
2019-07-17 23:35:00 +02:00
|
|
|
.assigned-label-transphobic { outline: 1px solid var(--ShinigamiEyesTransphobic) !important; }
|
|
|
|
.assigned-label-t-friendly { outline: 1px solid var(--ShinigamiEyesTFriendly) !important; }
|
2019-06-29 19:47:05 +02:00
|
|
|
`);
|
|
|
|
} else if (hostname == 'twitter.com') {
|
|
|
|
myself = getIdentifier(<HTMLAnchorElement>document.querySelector('.DashUserDropdown-userInfo a'));
|
|
|
|
addStyleSheet(`
|
|
|
|
.pretty-link b, .pretty-link s {
|
|
|
|
color: inherit !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
a.show-thread-link, a.ThreadedConversation-moreRepliesLink {
|
|
|
|
color: inherit !important;
|
|
|
|
}
|
|
|
|
.fullname,
|
|
|
|
.stream-item a:hover .fullname,
|
|
|
|
.stream-item a:active .fullname
|
|
|
|
{color:inherit;}
|
|
|
|
`);
|
|
|
|
} else if (hostname == 'reddit.com') {
|
|
|
|
myself = getIdentifier(<HTMLAnchorElement>document.querySelector('#header-bottom-right .user a'));
|
2018-11-16 21:51:31 +01:00
|
|
|
if (!myself) {
|
2019-06-29 19:47:05 +02:00
|
|
|
let m = document.querySelector('#USER_DROPDOWN_ID');
|
2018-11-16 21:51:31 +01:00
|
|
|
if (m) {
|
2019-06-29 19:47:05 +02:00
|
|
|
let username = [...m.querySelectorAll('*')].filter(x => x.childNodes.length == 1 && x.firstChild.nodeType == 3).map(x => x.textContent)[0]
|
|
|
|
if (username) myself = 'reddit.com/user/' + username;
|
2018-11-16 21:51:31 +01:00
|
|
|
}
|
2018-09-16 12:27:42 +02:00
|
|
|
}
|
2019-06-29 19:47:05 +02:00
|
|
|
addStyleSheet(`
|
|
|
|
.author { color: #369 !important;}
|
|
|
|
`);
|
2018-09-16 12:27:42 +02:00
|
|
|
}
|
2019-06-29 19:47:05 +02:00
|
|
|
}
|
2018-11-16 21:51:31 +01:00
|
|
|
|
2019-06-29 19:54:25 +02:00
|
|
|
function addStyleSheet(css: string) {
|
2019-06-29 19:47:05 +02:00
|
|
|
const style = document.createElement('style');
|
|
|
|
style.textContent = css;
|
|
|
|
document.head.appendChild(style);
|
2018-10-30 18:10:57 +01:00
|
|
|
}
|
|
|
|
|
2018-12-16 17:36:19 +01:00
|
|
|
function maybeDisableCustomCss() {
|
2019-06-29 19:54:25 +02:00
|
|
|
var shouldDisable: (s: { ownerNode: HTMLElement }) => boolean = null;
|
2018-12-16 17:36:19 +01:00
|
|
|
if (hostname == 'twitter.com') shouldDisable = x => x.ownerNode && x.ownerNode.id && x.ownerNode.id.startsWith('user-style');
|
|
|
|
else if (hostname == 'medium.com') shouldDisable = x => x.ownerNode && x.ownerNode.className && x.ownerNode.className == 'js-collectionStyle';
|
|
|
|
else if (hostname == 'disqus.com') shouldDisable = x => x.ownerNode && x.ownerNode.id && x.ownerNode.id.startsWith('css_');
|
2018-09-16 12:27:42 +02:00
|
|
|
|
2018-12-16 17:36:19 +01:00
|
|
|
if (shouldDisable)
|
2019-06-29 19:47:05 +02:00
|
|
|
[...document.styleSheets].filter(<any>shouldDisable).forEach(x => x.disabled = true);
|
2018-11-16 20:35:31 +01:00
|
|
|
}
|
|
|
|
|
2018-09-16 12:27:42 +02:00
|
|
|
function init() {
|
2019-10-06 13:04:11 +02:00
|
|
|
isSocialNetwork = [
|
|
|
|
'facebook.com',
|
|
|
|
'youtube.com',
|
|
|
|
'reddit.com',
|
|
|
|
'twitter.com',
|
|
|
|
'medium.com',
|
|
|
|
'disqus.com',
|
|
|
|
'rationalwiki.org',
|
|
|
|
'duckduckgo.com',
|
|
|
|
'bing.com',
|
|
|
|
].includes(hostname) ||
|
|
|
|
domainIs(hostname, 'tumblr.com') ||
|
|
|
|
domainIs(hostname, 'wikipedia.org') ||
|
|
|
|
/^google(\.co)?\.\w+$/.test(hostname);
|
|
|
|
|
2018-11-16 21:51:31 +01:00
|
|
|
fixupSiteStyles();
|
2018-12-16 17:36:19 +01:00
|
|
|
|
2019-06-29 19:47:05 +02:00
|
|
|
if (domainIs(hostname, 'youtube.com')) {
|
2018-11-16 21:51:31 +01:00
|
|
|
setInterval(updateYouTubeChannelHeader, 300);
|
2019-05-12 16:07:51 +02:00
|
|
|
setInterval(updateAllLabels, 6000);
|
2018-11-16 21:51:31 +01:00
|
|
|
}
|
2019-07-28 07:20:33 +02:00
|
|
|
if (hostname == 'twitter.com') {
|
|
|
|
setInterval(updateTwitterClasses, 800);
|
|
|
|
}
|
2018-11-16 21:51:31 +01:00
|
|
|
|
2019-10-06 13:04:11 +02:00
|
|
|
document.addEventListener('contextmenu', evt => {
|
|
|
|
lastRightClickedElement = <HTMLElement>evt.target;
|
|
|
|
}, true);
|
|
|
|
|
2018-11-16 21:51:31 +01:00
|
|
|
maybeDisableCustomCss();
|
2018-09-16 12:27:42 +02:00
|
|
|
updateAllLabels();
|
2018-12-16 17:36:19 +01:00
|
|
|
|
2019-10-06 13:04:11 +02:00
|
|
|
if (isSocialNetwork) {
|
|
|
|
var observer = new MutationObserver(mutationsList => {
|
|
|
|
maybeDisableCustomCss();
|
|
|
|
for (const mutation of mutationsList) {
|
|
|
|
if (mutation.type == 'childList') {
|
|
|
|
for (const node of mutation.addedNodes) {
|
|
|
|
if (node instanceof HTMLAnchorElement) {
|
|
|
|
initLink(node);
|
|
|
|
}
|
|
|
|
if (node instanceof HTMLElement) {
|
|
|
|
for (const subnode of node.querySelectorAll('a')) {
|
|
|
|
initLink(subnode);
|
|
|
|
}
|
2018-09-16 12:27:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-06 13:04:11 +02:00
|
|
|
solvePendingLabels();
|
|
|
|
});
|
2018-09-16 12:27:42 +02:00
|
|
|
|
2019-10-06 13:04:11 +02:00
|
|
|
observer.observe(document.body, {
|
|
|
|
childList: true,
|
|
|
|
subtree: true
|
|
|
|
});
|
|
|
|
}
|
2018-09-16 12:27:42 +02:00
|
|
|
}
|
|
|
|
|
2019-06-29 19:54:25 +02:00
|
|
|
var lastRightClickedElement: HTMLElement = null;
|
|
|
|
var lastAppliedYouTubeUrl: string = null;
|
|
|
|
var lastAppliedYouTubeTitle: string = null;
|
2018-10-30 18:10:57 +01:00
|
|
|
|
2019-08-03 12:40:29 +02:00
|
|
|
var lastAppliedTwitterUrl: string = null;
|
|
|
|
|
2019-07-28 07:31:24 +02:00
|
|
|
function updateTwitterClasses() {
|
2019-08-03 12:40:29 +02:00
|
|
|
if (location.href != lastAppliedTwitterUrl) {
|
|
|
|
setTimeout(updateAllLabels, 200);
|
|
|
|
lastAppliedTwitterUrl = location.href;
|
|
|
|
}
|
2019-07-28 07:20:33 +02:00
|
|
|
for (const a of document.querySelectorAll('a')) {
|
|
|
|
if (a.assignedCssLabel && !a.classList.contains('has-assigned-label')) {
|
|
|
|
a.classList.add('assigned-label-' + a.assignedCssLabel);
|
2019-07-28 07:31:24 +02:00
|
|
|
a.classList.add('has-assigned-label');
|
2019-07-28 07:20:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-16 17:36:19 +01:00
|
|
|
function updateYouTubeChannelHeader() {
|
2018-10-30 18:10:57 +01:00
|
|
|
var url = window.location.href;
|
2019-09-14 19:32:49 +02:00
|
|
|
var title = <HTMLElement>document.querySelector('#channel-header ytd-channel-name yt-formatted-string');
|
|
|
|
if (title && !title.parentElement.offsetParent) title = null;
|
2018-10-30 18:10:57 +01:00
|
|
|
var currentTitle = title ? title.textContent : null;
|
|
|
|
|
2018-12-16 17:36:19 +01:00
|
|
|
if (url == lastAppliedYouTubeUrl && currentTitle == lastAppliedYouTubeTitle) return;
|
2018-10-30 18:10:57 +01:00
|
|
|
lastAppliedYouTubeUrl = url;
|
|
|
|
lastAppliedYouTubeTitle = currentTitle;
|
2018-12-16 17:36:19 +01:00
|
|
|
|
|
|
|
if (currentTitle) {
|
2019-06-29 15:41:37 +02:00
|
|
|
var replacement = <HTMLAnchorElement>document.getElementById('channel-title-replacement');
|
2018-12-16 17:36:19 +01:00
|
|
|
if (!replacement) {
|
2019-06-29 15:41:37 +02:00
|
|
|
replacement = <HTMLAnchorElement>document.createElement('A');
|
2018-10-30 18:10:57 +01:00
|
|
|
replacement.id = 'channel-title-replacement'
|
|
|
|
replacement.className = title.className;
|
|
|
|
title.parentNode.insertBefore(replacement, title.nextSibling);
|
|
|
|
title.style.display = 'none';
|
|
|
|
replacement.style.fontSize = '2.4rem';
|
|
|
|
replacement.style.fontWeight = '400';
|
|
|
|
replacement.style.lineHeight = '3rem';
|
|
|
|
replacement.style.textDecoration = 'none';
|
2020-12-26 07:52:52 +01:00
|
|
|
replacement.style.color = 'var(--yt-spec-text-primary)';
|
2018-10-30 18:10:57 +01:00
|
|
|
}
|
|
|
|
replacement.textContent = lastAppliedYouTubeTitle;
|
|
|
|
replacement.href = lastAppliedYouTubeUrl;
|
|
|
|
}
|
|
|
|
updateAllLabels();
|
2019-03-03 21:27:45 +01:00
|
|
|
setTimeout(updateAllLabels, 2000);
|
2019-05-12 16:07:51 +02:00
|
|
|
setTimeout(updateAllLabels, 4000);
|
2018-10-30 18:10:57 +01:00
|
|
|
}
|
|
|
|
|
2019-06-29 15:41:37 +02:00
|
|
|
function updateAllLabels(refresh?: boolean) {
|
2018-09-16 12:27:42 +02:00
|
|
|
if (refresh) knownLabels = {};
|
2019-10-06 13:04:11 +02:00
|
|
|
if (isSocialNetwork) {
|
|
|
|
for (const a of document.getElementsByTagName('a')) {
|
|
|
|
initLink(a);
|
|
|
|
}
|
2018-09-16 12:27:42 +02:00
|
|
|
}
|
|
|
|
solvePendingLabels();
|
|
|
|
}
|
|
|
|
|
2019-06-29 19:47:05 +02:00
|
|
|
var knownLabels: LabelMap = {};
|
2019-07-17 23:35:00 +02:00
|
|
|
var currentlyAppliedTheme = '_none_';
|
2018-09-16 12:27:42 +02:00
|
|
|
|
2019-06-29 19:54:25 +02:00
|
|
|
var labelsToSolve: LabelToSolve[] = [];
|
2018-09-16 12:27:42 +02:00
|
|
|
function solvePendingLabels() {
|
|
|
|
if (!labelsToSolve.length) return;
|
|
|
|
var uniqueIdentifiers = Array.from(new Set(labelsToSolve.map(x => x.identifier)));
|
|
|
|
var tosolve = labelsToSolve;
|
|
|
|
labelsToSolve = [];
|
2019-06-29 19:47:05 +02:00
|
|
|
browser.runtime.sendMessage<ShinigamiEyesCommand, LabelMap>({ ids: uniqueIdentifiers, myself: <string>myself }, (response: LabelMap) => {
|
2019-07-17 23:35:00 +02:00
|
|
|
const theme = response[':theme'];
|
|
|
|
if (theme != currentlyAppliedTheme) {
|
|
|
|
if (currentlyAppliedTheme) document.body.classList.remove('shinigami-eyes-theme-' + currentlyAppliedTheme);
|
|
|
|
if (theme) document.body.classList.add('shinigami-eyes-theme-' + theme);
|
|
|
|
currentlyAppliedTheme = theme;
|
|
|
|
}
|
2019-06-29 15:41:37 +02:00
|
|
|
for (const item of tosolve) {
|
2019-07-17 23:35:00 +02:00
|
|
|
const label = response[item.identifier];
|
2018-09-16 12:27:42 +02:00
|
|
|
knownLabels[item.identifier] = label || '';
|
|
|
|
applyLabel(item.element, item.identifier);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-06-29 19:47:05 +02:00
|
|
|
function applyLabel(a: HTMLAnchorElement, identifier: string) {
|
2018-09-16 12:27:42 +02:00
|
|
|
if (a.assignedCssLabel) {
|
|
|
|
a.classList.remove('assigned-label-' + a.assignedCssLabel);
|
|
|
|
a.classList.remove('has-assigned-label');
|
|
|
|
}
|
2018-12-03 22:19:33 +01:00
|
|
|
|
|
|
|
a.assignedCssLabel = knownLabels[identifier] || '';
|
|
|
|
|
2018-09-16 12:27:42 +02:00
|
|
|
if (a.assignedCssLabel) {
|
|
|
|
a.classList.add('assigned-label-' + a.assignedCssLabel);
|
|
|
|
a.classList.add('has-assigned-label');
|
2018-12-03 22:19:54 +01:00
|
|
|
if (hostname == 'twitter.com')
|
|
|
|
a.classList.remove('u-textInheritColor');
|
2018-09-16 12:27:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-29 15:41:37 +02:00
|
|
|
function initLink(a: HTMLAnchorElement) {
|
2018-09-16 12:27:42 +02:00
|
|
|
var identifier = getIdentifier(a);
|
2019-06-29 19:54:25 +02:00
|
|
|
if (!identifier) {
|
2019-08-03 12:40:29 +02:00
|
|
|
if (hostname == 'youtube.com' || hostname == 'twitter.com')
|
2019-03-03 21:27:45 +01:00
|
|
|
applyLabel(a, '');
|
|
|
|
return;
|
|
|
|
}
|
2018-09-16 12:27:42 +02:00
|
|
|
|
|
|
|
var label = knownLabels[identifier];
|
|
|
|
if (label === undefined) {
|
|
|
|
labelsToSolve.push({ element: a, identifier: identifier });
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
applyLabel(a, identifier);
|
|
|
|
}
|
|
|
|
|
2019-06-29 19:47:05 +02:00
|
|
|
function domainIs(host: string, baseDomain: string) {
|
|
|
|
if (baseDomain.length > host.length) return false;
|
|
|
|
if (baseDomain.length == host.length) return baseDomain == host;
|
|
|
|
var k = host.charCodeAt(host.length - baseDomain.length - 1);
|
|
|
|
if (k == 0x2E /* . */) return host.endsWith(baseDomain);
|
2018-09-16 12:27:42 +02:00
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
|
2019-06-29 19:47:05 +02:00
|
|
|
function getPartialPath(path: string, num: number) {
|
2018-09-16 12:27:42 +02:00
|
|
|
var m = path.split('/')
|
|
|
|
m = m.slice(1, 1 + num);
|
|
|
|
if (m.length && !m[m.length - 1]) m.length--;
|
2019-01-13 17:17:01 +01:00
|
|
|
if (m.length != num) return '!!'
|
2018-09-16 12:27:42 +02:00
|
|
|
return '/' + m.join('/');
|
|
|
|
}
|
2019-06-29 19:47:05 +02:00
|
|
|
function getPathPart(path: string, index: number) {
|
|
|
|
return path.split('/')[index + 1] || null;
|
2018-12-16 11:32:37 +01:00
|
|
|
}
|
2018-09-16 12:27:42 +02:00
|
|
|
|
2019-06-29 19:47:05 +02:00
|
|
|
function captureRegex(str: string, regex: RegExp) {
|
2018-12-16 17:36:19 +01:00
|
|
|
if (!str) return null;
|
2018-10-22 18:56:44 +02:00
|
|
|
var match = str.match(regex);
|
2018-12-16 17:36:19 +01:00
|
|
|
if (match && match[1]) return match[1];
|
2018-10-22 18:56:44 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-09-16 12:27:42 +02:00
|
|
|
function getCurrentFacebookPageId() {
|
|
|
|
|
|
|
|
// page
|
2019-06-29 15:41:37 +02:00
|
|
|
var elem = <HTMLAnchorElement>document.querySelector("a[rel=theater][aria-label='Profile picture']");
|
2018-09-16 12:27:42 +02:00
|
|
|
if (elem) {
|
2018-10-22 18:56:44 +02:00
|
|
|
var p = captureRegex(elem.href, /facebook\.com\/(\d+)/)
|
|
|
|
if (p) return p;
|
2018-09-16 12:27:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// page (does not work if page is loaded directly)
|
|
|
|
elem = document.querySelector("[ajaxify^='/page_likers_and_visitors_dialog']")
|
2018-10-22 18:56:44 +02:00
|
|
|
if (elem) return captureRegex(elem.getAttribute('ajaxify'), /\/(\d+)\//);
|
2018-09-16 12:27:42 +02:00
|
|
|
|
|
|
|
// group
|
|
|
|
elem = document.querySelector("[id^='headerAction_']");
|
2018-10-22 18:56:44 +02:00
|
|
|
if (elem) return captureRegex(elem.id, /_(\d+)/);
|
2018-09-16 12:27:42 +02:00
|
|
|
|
|
|
|
// profile
|
|
|
|
elem = document.querySelector('#pagelet_timeline_main_column');
|
|
|
|
if (elem && elem.dataset.gt) return JSON.parse(elem.dataset.gt).profile_owner;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-04-13 10:19:27 +02:00
|
|
|
function getIdentifier(link: string | HTMLAnchorElement, originalTarget?: HTMLElement) {
|
2018-12-16 17:36:19 +01:00
|
|
|
try {
|
2020-04-13 10:19:27 +02:00
|
|
|
var k = link instanceof Node ? getIdentifierFromElementImpl(link, originalTarget) : getIdentifierFromURLImpl(tryParseURL(link));
|
2019-02-08 20:43:06 +01:00
|
|
|
if (!k || k.indexOf('!') != -1) return null;
|
2019-01-14 23:11:06 +01:00
|
|
|
return k.toLowerCase();
|
2018-12-16 17:36:19 +01:00
|
|
|
} catch (e) {
|
2019-06-29 19:47:05 +02:00
|
|
|
console.warn("Unable to get identifier for " + link);
|
2018-10-22 18:56:44 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-13 10:19:27 +02:00
|
|
|
function isFacebookPictureLink(element: HTMLAnchorElement) {
|
|
|
|
var href = element.href;
|
|
|
|
return href && (href.includes('/photo/') || href.includes('/photo.php'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function getIdentifierFromElementImpl(element: HTMLAnchorElement, originalTarget: HTMLElement): string {
|
2019-06-29 19:47:05 +02:00
|
|
|
if (!element) return null;
|
2018-09-16 12:27:42 +02:00
|
|
|
|
2019-06-29 19:47:05 +02:00
|
|
|
const dataset = element.dataset;
|
2019-02-08 21:00:04 +01:00
|
|
|
|
2019-06-29 19:47:05 +02:00
|
|
|
if (hostname == 'reddit.com') {
|
|
|
|
const parent = element.parentElement;
|
|
|
|
if (parent && parent.classList.contains('domain') && element.textContent.startsWith('self.')) return null;
|
|
|
|
} else if (hostname == 'disqus.com') {
|
|
|
|
if (element.classList && element.classList.contains('time-ago')) return null;
|
|
|
|
} else if (hostname == 'facebook.com') {
|
|
|
|
const parent = element.parentElement;
|
2020-04-13 09:36:48 +02:00
|
|
|
const firstChild = <HTMLElement>element.firstChild;
|
2018-09-16 12:27:42 +02:00
|
|
|
if (parent && (parent.tagName == 'H1' || parent.id == 'fb-timeline-cover-name')) {
|
2019-06-29 15:41:37 +02:00
|
|
|
const id = getCurrentFacebookPageId();
|
2018-09-16 12:27:42 +02:00
|
|
|
//console.log('Current fb page: ' + id)
|
|
|
|
if (id)
|
|
|
|
return 'facebook.com/' + id;
|
|
|
|
}
|
2019-03-01 00:04:11 +01:00
|
|
|
|
|
|
|
// comment timestamp
|
2020-04-13 09:36:48 +02:00
|
|
|
if (firstChild && firstChild.tagName == 'ABBR' && element.lastChild == firstChild) return null;
|
2019-06-29 19:54:25 +02:00
|
|
|
|
2019-03-01 00:04:11 +01:00
|
|
|
// post 'see more'
|
2019-06-29 19:47:05 +02:00
|
|
|
if (element.classList.contains('see_more_link')) return null;
|
2019-03-01 00:04:11 +01:00
|
|
|
|
|
|
|
// post 'continue reading'
|
|
|
|
if (parent && parent.classList.contains('text_exposed_link')) return null;
|
|
|
|
|
2020-04-13 09:36:48 +02:00
|
|
|
// React comment timestamp
|
|
|
|
if (parent && parent.tagName == 'LI') return null;
|
|
|
|
|
|
|
|
// React post timestamp
|
2020-12-26 07:56:48 +01:00
|
|
|
if (element.getAttribute('role') == 'link' && parent && parent.tagName == 'SPAN' && firstChild && firstChild.tagName == 'SPAN' && firstChild.tabIndex == 0)
|
|
|
|
return null;
|
2019-03-01 00:04:11 +01:00
|
|
|
|
2020-04-13 10:05:46 +02:00
|
|
|
// React big profile picture (user or page)
|
2020-04-13 10:19:27 +02:00
|
|
|
if (originalTarget instanceof SVGImageElement && isFacebookPictureLink(element) && !getMatchingAncestorByCss(element, '[role=article]')) {
|
|
|
|
return getIdentifier(window.location.href);
|
|
|
|
}
|
|
|
|
|
|
|
|
// React cover picture
|
|
|
|
if (originalTarget instanceof HTMLImageElement && isFacebookPictureLink(element) && element.getAttribute('aria-label') && !getMatchingAncestorByCss(element, '[role=article]')) {
|
2020-04-13 10:05:46 +02:00
|
|
|
return getIdentifier(window.location.href);
|
|
|
|
}
|
|
|
|
|
2019-06-29 19:47:05 +02:00
|
|
|
if (dataset) {
|
|
|
|
const hovercard = dataset.hovercard;
|
2018-09-16 12:27:42 +02:00
|
|
|
if (hovercard) {
|
2019-06-29 15:41:37 +02:00
|
|
|
const id = captureRegex(hovercard, /id=(\d+)/);
|
2018-09-16 12:27:42 +02:00
|
|
|
if (id)
|
|
|
|
return 'facebook.com/' + id;
|
|
|
|
}
|
2019-03-01 00:04:11 +01:00
|
|
|
|
|
|
|
// post Comments link
|
2019-06-29 19:47:05 +02:00
|
|
|
if (dataset.testid == 'UFI2CommentsCount/root') return null;
|
2019-06-29 19:54:25 +02:00
|
|
|
|
2019-07-14 21:59:01 +02:00
|
|
|
// notification
|
|
|
|
if (dataset.testid == 'notif_list_item_link') return null;
|
|
|
|
|
2019-03-01 00:04:11 +01:00
|
|
|
// post Comments link
|
2019-06-29 19:47:05 +02:00
|
|
|
if (dataset.commentPreludeRef) return null;
|
2019-03-01 00:04:11 +01:00
|
|
|
|
|
|
|
// page left sidebar
|
2019-06-29 19:47:05 +02:00
|
|
|
if (dataset.endpoint) return null;
|
2019-03-01 00:04:11 +01:00
|
|
|
|
2019-03-03 21:02:57 +01:00
|
|
|
// profile tabs
|
2019-06-29 19:47:05 +02:00
|
|
|
if (dataset.tabKey) return null;
|
2019-03-03 21:02:57 +01:00
|
|
|
|
2019-06-29 19:47:05 +02:00
|
|
|
const gt = dataset.gt;
|
2018-09-16 12:27:42 +02:00
|
|
|
if (gt) {
|
2019-06-29 15:41:37 +02:00
|
|
|
const gtParsed = JSON.parse(gt);
|
2018-09-16 12:27:42 +02:00
|
|
|
if (gtParsed.engagement && gtParsed.engagement.eng_tid) {
|
|
|
|
return 'facebook.com/' + gtParsed.engagement.eng_tid;
|
|
|
|
}
|
|
|
|
}
|
2019-03-01 00:04:11 +01:00
|
|
|
|
|
|
|
// comment interaction buttons
|
2019-06-29 19:47:05 +02:00
|
|
|
if (dataset.sigil) return null;
|
2019-03-01 00:04:11 +01:00
|
|
|
|
2019-06-29 19:47:05 +02:00
|
|
|
let p = <HTMLElement>element;
|
2018-09-16 12:27:42 +02:00
|
|
|
while (p) {
|
2019-06-29 15:41:37 +02:00
|
|
|
const bt = p.dataset.bt;
|
2018-09-16 12:27:42 +02:00
|
|
|
if (bt) {
|
2019-06-29 15:41:37 +02:00
|
|
|
const btParsed = JSON.parse(bt);
|
2018-09-16 12:27:42 +02:00
|
|
|
if (btParsed.id) return 'facebook.com/' + btParsed.id;
|
|
|
|
}
|
|
|
|
p = p.parentElement;
|
|
|
|
}
|
|
|
|
}
|
2019-07-28 07:31:24 +02:00
|
|
|
} else if (hostname == 'twitter.com') {
|
2019-07-28 07:31:04 +02:00
|
|
|
if (dataset && dataset.expandedUrl) return getIdentifier(dataset.expandedUrl);
|
|
|
|
if (element.href.startsWith('https://t.co/')) {
|
|
|
|
const title = element.title;
|
|
|
|
if (title && (title.startsWith('http://') || title.startsWith('https://')))
|
|
|
|
return getIdentifier(title);
|
|
|
|
const content = element.textContent;
|
2020-12-26 07:56:15 +01:00
|
|
|
if (!content.includes(' ') && content.includes('.') && !content.includes('…')) {
|
|
|
|
const url = content.startsWith('http://') || content.startsWith('https://') ? content : 'http://' + content;
|
|
|
|
return getIdentifier(url);
|
|
|
|
}
|
2019-07-28 07:31:04 +02:00
|
|
|
}
|
2019-07-28 07:34:48 +02:00
|
|
|
} else if (domainIs(hostname, 'wikipedia.org')) {
|
|
|
|
if (element.classList.contains('interlanguage-link-target')) return null;
|
2018-09-16 12:27:42 +02:00
|
|
|
}
|
2019-07-14 21:55:23 +02:00
|
|
|
|
2020-12-26 07:55:45 +01:00
|
|
|
if (element.classList.contains('tumblelog')) return element.textContent.replace('@', '') + '.tumblr.com';
|
2019-07-14 21:55:23 +02:00
|
|
|
|
2019-06-29 19:47:05 +02:00
|
|
|
const href = element.href;
|
2019-10-06 11:10:23 +02:00
|
|
|
if (href && (!href.endsWith('#') || href.includes('&stick='))) return getIdentifierFromURLImpl(tryParseURL(href));
|
2019-06-29 19:47:05 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-06-29 19:54:25 +02:00
|
|
|
function tryParseURL(urlstr: string) {
|
2018-09-16 12:27:42 +02:00
|
|
|
if (!urlstr) return null;
|
|
|
|
try {
|
2019-06-29 19:47:05 +02:00
|
|
|
const url = new URL(urlstr);
|
|
|
|
if (url.protocol != 'http:' && url.protocol != 'https:') return null;
|
|
|
|
return url;
|
2019-06-29 19:54:25 +02:00
|
|
|
} catch (e) {
|
2018-09-16 12:27:42 +02:00
|
|
|
return null;
|
|
|
|
}
|
2019-06-29 19:47:05 +02:00
|
|
|
}
|
2018-09-16 12:27:42 +02:00
|
|
|
|
2019-10-17 13:30:42 +02:00
|
|
|
function tryUnwrapNestedURL(url: URL): URL {
|
2019-06-29 19:54:25 +02:00
|
|
|
if (!url) return null;
|
2021-07-05 09:08:13 +02:00
|
|
|
if (domainIs(url.host, 'youtube.com') && url.pathname == '/redirect') {
|
|
|
|
const q = url.searchParams.get('q');
|
|
|
|
if (q && !q.startsWith('http:') && !q.startsWith('https:') && q.includes('.')) return tryParseURL('http://' + q);
|
|
|
|
}
|
2018-09-16 12:27:42 +02:00
|
|
|
if (url.href.indexOf('http', 1) != -1) {
|
2019-06-29 19:47:05 +02:00
|
|
|
if (url.pathname.startsWith('/intl/')) return null; // facebook language switch links
|
|
|
|
|
|
|
|
// const values = url.searchParams.values()
|
|
|
|
// HACK: values(...) is not iterable on facebook (babel polyfill?)
|
|
|
|
const values = url.search.split('&').map(x => {
|
2020-12-26 07:55:09 +01:00
|
|
|
if (x.startsWith('ref_url=')) return '';
|
2019-06-29 19:47:05 +02:00
|
|
|
const eq = x.indexOf('=');
|
|
|
|
return eq == -1 ? '' : decodeURIComponent(x.substr(eq + 1));
|
|
|
|
});
|
|
|
|
|
|
|
|
for (const value of values) {
|
|
|
|
if (value.startsWith('http:') || value.startsWith('https:')) {
|
2019-10-17 13:30:42 +02:00
|
|
|
return tryParseURL(value);
|
2018-09-16 12:27:42 +02:00
|
|
|
}
|
|
|
|
}
|
2019-06-29 19:47:05 +02:00
|
|
|
const newurl = tryParseURL(url.href.substring(url.href.indexOf('http', 1)));
|
2019-10-17 13:30:42 +02:00
|
|
|
if (newurl) return newurl;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getIdentifierFromURLImpl(url: URL): string {
|
|
|
|
if (!url) return null;
|
|
|
|
|
|
|
|
// nested urls
|
|
|
|
const nested = tryUnwrapNestedURL(url);
|
|
|
|
if (nested) {
|
|
|
|
return getIdentifierFromURLImpl(nested);
|
2018-09-16 12:27:42 +02:00
|
|
|
}
|
|
|
|
|
2019-06-29 19:47:05 +02:00
|
|
|
// fb group member badge
|
|
|
|
if (url.pathname.includes('/badge_member_list/')) return null;
|
|
|
|
|
2019-06-29 15:41:37 +02:00
|
|
|
let host = url.hostname;
|
2019-07-18 00:08:17 +02:00
|
|
|
const searchParams = url.searchParams;
|
2019-06-29 19:47:05 +02:00
|
|
|
if (domainIs(host, 'web.archive.org')) {
|
2019-06-29 15:41:37 +02:00
|
|
|
const match = captureRegex(url.href, /\/web\/\w+\/(.*)/);
|
2018-09-16 12:27:42 +02:00
|
|
|
if (!match) return null;
|
2019-06-29 19:47:05 +02:00
|
|
|
return getIdentifierFromURLImpl(tryParseURL('http://' + match));
|
2018-09-16 12:27:42 +02:00
|
|
|
}
|
2019-06-29 19:47:05 +02:00
|
|
|
|
2018-09-16 12:27:42 +02:00
|
|
|
if (host.startsWith('www.')) host = host.substring(4);
|
|
|
|
|
2020-09-14 11:48:25 +02:00
|
|
|
const pathArray = url.pathname.split('/');
|
|
|
|
|
2019-06-29 19:47:05 +02:00
|
|
|
if (domainIs(host, 'facebook.com')) {
|
2020-12-26 09:56:35 +01:00
|
|
|
if (searchParams.get('story_fbid')) return null;
|
2019-07-18 00:08:17 +02:00
|
|
|
const fbId = searchParams.get('id');
|
2019-06-29 15:41:37 +02:00
|
|
|
const p = url.pathname.replace('/pg/', '/');
|
2020-09-14 11:48:25 +02:00
|
|
|
const isGroup = p.startsWith('/groups/');
|
|
|
|
if (isGroup && p.includes('/user/')) return 'facebook.com/' + pathArray[4]; // fb.com/groups/.../user/...
|
|
|
|
return 'facebook.com/' + (fbId || getPartialPath(p, isGroup ? 2 : 1).substring(1));
|
2019-06-29 19:47:05 +02:00
|
|
|
} else if (domainIs(host, 'reddit.com')) {
|
2019-06-29 15:41:37 +02:00
|
|
|
const pathname = url.pathname.replace('/u/', '/user/');
|
2019-01-13 18:25:47 +01:00
|
|
|
if (!pathname.startsWith('/user/') && !pathname.startsWith('/r/')) return null;
|
2019-06-29 19:54:25 +02:00
|
|
|
if (pathname.includes('/comments/') && hostname == 'reddit.com') return null;
|
2019-06-29 19:47:05 +02:00
|
|
|
return 'reddit.com' + getPartialPath(pathname, 2);
|
|
|
|
} else if (domainIs(host, 'twitter.com')) {
|
|
|
|
return 'twitter.com' + getPartialPath(url.pathname, 1);
|
|
|
|
} else if (domainIs(host, 'youtube.com')) {
|
2021-03-15 18:06:10 +01:00
|
|
|
const pathname = url.pathname;
|
|
|
|
if (pathname.startsWith('/user/') || pathname.startsWith('/c/') || pathname.startsWith('/channel/'))
|
|
|
|
return 'youtube.com' + getPartialPath(pathname, 2);
|
|
|
|
return 'youtube.com' + getPartialPath(pathname, 1);
|
2019-06-29 19:47:05 +02:00
|
|
|
} else if (domainIs(host, 'disqus.com') && url.pathname.startsWith('/by/')) {
|
|
|
|
return 'disqus.com' + getPartialPath(url.pathname, 2);
|
|
|
|
} else if (domainIs(host, 'medium.com')) {
|
2020-12-26 08:14:42 +01:00
|
|
|
const hostParts = host.split('.');
|
2021-03-14 15:22:07 +01:00
|
|
|
if (hostParts.length == 3 && hostParts[0] != 'www') {
|
2020-12-26 08:14:42 +01:00
|
|
|
return host;
|
|
|
|
}
|
2019-06-29 19:47:05 +02:00
|
|
|
return 'medium.com' + getPartialPath(url.pathname.replace('/t/', '/'), 1);
|
|
|
|
} else if (domainIs(host, 'tumblr.com')) {
|
2018-12-16 17:36:19 +01:00
|
|
|
if (url.pathname.startsWith('/register/follow/')) {
|
2019-06-29 19:47:05 +02:00
|
|
|
const name = getPathPart(url.pathname, 2);
|
2018-12-16 11:32:37 +01:00
|
|
|
return name ? name + '.tumblr.com' : null;
|
|
|
|
}
|
2018-12-16 17:36:19 +01:00
|
|
|
if (host != 'www.tumblr.com' && host != 'assets.tumblr.com' && host.indexOf('.media.') == -1) {
|
2019-01-14 23:11:06 +01:00
|
|
|
if (!url.pathname.startsWith('/tagged/')) return url.host;
|
2018-12-16 11:32:37 +01:00
|
|
|
}
|
|
|
|
return null;
|
2019-06-29 19:47:05 +02:00
|
|
|
} else if (domainIs(host, 'wikipedia.org') || domainIs(host, 'rationalwiki.org')) {
|
2021-03-14 14:01:10 +01:00
|
|
|
const pathname = url.pathname;
|
|
|
|
if (url.hash) return null;
|
2021-03-14 15:22:07 +01:00
|
|
|
if (pathname == '/w/index.php' && searchParams.get('action') == 'edit') {
|
|
|
|
const title = searchParams.get('title');
|
|
|
|
if (title && title.startsWith('User:')) {
|
|
|
|
return 'wikipedia.org/wiki/' + title;
|
|
|
|
}
|
|
|
|
}
|
2021-03-14 14:01:10 +01:00
|
|
|
if (pathname.startsWith('/wiki/Special:Contributions/') && url.href == window.location.href)
|
|
|
|
return 'wikipedia.org/wiki/User:' + pathArray[3];
|
|
|
|
if (pathname.startsWith('/wiki/User:'))
|
|
|
|
return 'wikipedia.org/wiki/User:' + pathArray[2].split(':')[1];
|
|
|
|
if (pathname.includes(':')) return null;
|
|
|
|
if (pathname.startsWith('/wiki/')) return 'wikipedia.org' + decodeURIComponent(getPartialPath(pathname, 2));
|
2019-01-13 17:16:37 +01:00
|
|
|
else return null;
|
2019-06-29 19:47:05 +02:00
|
|
|
} else if (host.indexOf('.blogspot.') != -1) {
|
2019-06-29 15:41:37 +02:00
|
|
|
const m = captureRegex(host, /([a-zA-Z0-9\-]*)\.blogspot/);
|
2019-01-14 23:11:06 +01:00
|
|
|
if (m) return m + '.blogspot.com';
|
2019-06-29 19:47:05 +02:00
|
|
|
else return null;
|
2019-07-28 07:31:24 +02:00
|
|
|
} else if (host.includes('google.')) {
|
|
|
|
if (url.pathname == '/search' && searchParams.get('stick') && !searchParams.get('tbm') && !searchParams.get('start')) {
|
2019-07-18 00:08:17 +02:00
|
|
|
const q = searchParams.get('q');
|
2019-07-28 07:31:24 +02:00
|
|
|
if (q) return 'wikipedia.org/wiki/' + q.replace(/\s/g, '_');
|
2019-07-18 00:08:17 +02:00
|
|
|
}
|
|
|
|
return null;
|
2019-06-29 19:47:05 +02:00
|
|
|
} else {
|
|
|
|
if (host.startsWith('m.')) host = host.substr(2);
|
|
|
|
return host;
|
2018-09-16 12:27:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
init();
|
|
|
|
|
2018-12-17 21:56:30 +01:00
|
|
|
var lastGeneratedLinkId = 0;
|
|
|
|
|
2020-03-12 12:02:02 +01:00
|
|
|
function getMatchingAncestor(node: HTMLElement, match: (node: HTMLElement) => boolean) {
|
2019-03-03 21:02:57 +01:00
|
|
|
while (node) {
|
2020-03-12 12:02:02 +01:00
|
|
|
if (match(node)) return node;
|
2019-03-03 21:02:57 +01:00
|
|
|
node = node.parentElement;
|
|
|
|
}
|
2020-03-12 12:02:02 +01:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getMatchingAncestorByCss(node: HTMLElement, cssMatch: string) {
|
|
|
|
return getMatchingAncestor(node, x => x.matches(cssMatch));
|
|
|
|
}
|
|
|
|
|
2020-12-26 07:54:24 +01:00
|
|
|
function getSnippet(node: HTMLElement) : HTMLElement {
|
2020-03-12 12:02:02 +01:00
|
|
|
if (hostname == 'facebook.com') {
|
2020-12-26 07:54:24 +01:00
|
|
|
const pathname = window.location.pathname;
|
|
|
|
const isPhotoPage = pathname.startsWith('/photo') || pathname.includes('/photos/') || pathname.startsWith('/video') || pathname.includes('/videos/');
|
|
|
|
if (isPhotoPage) {
|
|
|
|
const sidebar = document.querySelector('[role=complementary]');
|
|
|
|
if (sidebar) return sidebar.parentElement;
|
|
|
|
}
|
|
|
|
const isSearchPage = pathname.startsWith('/search/');
|
2020-03-12 12:02:02 +01:00
|
|
|
return getMatchingAncestor(node, x => {
|
2020-12-26 07:54:24 +01:00
|
|
|
if (x.getAttribute('role') == 'article' && (isSearchPage || x.getAttribute('aria-labelledby'))) return true;
|
2020-03-12 12:02:02 +01:00
|
|
|
var dataset = x.dataset;
|
|
|
|
if (!dataset) return false;
|
|
|
|
if (dataset.ftr) return true;
|
|
|
|
if (dataset.highlightTokens) return true;
|
|
|
|
if (dataset.gt && dataset.vistracking) return true;
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (hostname == 'reddit.com')
|
|
|
|
return getMatchingAncestorByCss(node, '.scrollerItem, .thing, .Comment');
|
|
|
|
if (hostname == 'twitter.com')
|
|
|
|
return getMatchingAncestorByCss(node, '.stream-item, .permalink-tweet-container, article');
|
|
|
|
if (hostname == 'disqus.com')
|
|
|
|
return getMatchingAncestorByCss(node, '.post-content');
|
|
|
|
if (hostname == 'medium.com')
|
|
|
|
return getMatchingAncestorByCss(node, '.streamItem, .streamItemConversationItem');
|
|
|
|
if (hostname == 'youtube.com')
|
|
|
|
return getMatchingAncestorByCss(node, 'ytd-comment-renderer, ytd-video-secondary-info-renderer');
|
|
|
|
if (hostname == 'tumblr.com')
|
2020-12-26 07:53:23 +01:00
|
|
|
return getMatchingAncestor(node, x => (x.dataset && !!(x.dataset.postId || x.dataset.id)) || x.classList.contains('post'));
|
2020-03-12 12:02:02 +01:00
|
|
|
|
2019-03-03 21:02:57 +01:00
|
|
|
return null;
|
2019-03-03 21:02:40 +01:00
|
|
|
}
|
|
|
|
|
2020-04-13 09:39:05 +02:00
|
|
|
function getBadIdentifierReason(identifier: string, url: string, target: HTMLElement) {
|
2019-10-06 16:31:46 +02:00
|
|
|
identifier = identifier || '';
|
|
|
|
url = url || '';
|
2019-10-17 13:30:42 +02:00
|
|
|
if (url) {
|
|
|
|
const nested = tryUnwrapNestedURL(tryParseURL(url));
|
|
|
|
if (nested) url = nested.href;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (identifier == 't.co') return 'Shortened link. Please follow the link and then mark the resulting page.';
|
2019-10-06 16:31:46 +02:00
|
|
|
if (
|
|
|
|
identifier.startsWith('reddit.com/user/') ||
|
|
|
|
identifier == 'twitter.com/threadreaderapp' ||
|
|
|
|
identifier == 'twitter.com/threader_app') return 'This is user is a bot.';
|
|
|
|
if (identifier == 'twitter.com/hashtag') return 'Hashtags cannot be labeled, only users.';
|
|
|
|
if (url.includes('youtube.com/watch')) return 'Only channels can be labeled, not specific videos.';
|
2019-10-07 21:07:36 +02:00
|
|
|
if (url.includes('reddit.com/') && url.includes('/comments/')) return 'Only users and subreddits can be labeled, not specific posts.';
|
|
|
|
if (url.includes('facebook.com') && (
|
|
|
|
url.includes('/posts/') ||
|
2020-04-13 09:36:48 +02:00
|
|
|
url.includes('/photo/') ||
|
2019-10-07 21:07:36 +02:00
|
|
|
url.includes('/photo.php') ||
|
2020-12-26 09:56:35 +01:00
|
|
|
url.includes('/permalink.php') ||
|
|
|
|
url.includes('/permalink/') ||
|
2019-10-07 21:07:36 +02:00
|
|
|
url.includes('/photos/'))) return 'Only pages, users and groups can be labeled, not specific posts or photos.';
|
2019-10-06 16:31:46 +02:00
|
|
|
if (url.includes('wiki') && url.includes('#')) return 'Wiki paragraphs cannot be labeled, only whole articles.';
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var previousConfirmationMessage: HTMLElement = null;
|
|
|
|
|
2020-04-13 09:39:05 +02:00
|
|
|
function displayConfirmation(identifier: string, label: LabelKind, badIdentifierReason: BadIdentifierReason, url: string, target: HTMLElement) {
|
2019-10-06 16:31:46 +02:00
|
|
|
if (previousConfirmationMessage) {
|
|
|
|
previousConfirmationMessage.remove();
|
|
|
|
previousConfirmationMessage = null;
|
|
|
|
}
|
|
|
|
if (!label) return;
|
|
|
|
if (isSocialNetwork && label != 'bad-identifier') return;
|
|
|
|
|
2019-10-06 14:29:26 +02:00
|
|
|
const confirmation = document.createElement('div');
|
2019-10-06 16:31:46 +02:00
|
|
|
const background =
|
|
|
|
label == 't-friendly' ? '#eaffcf' :
|
|
|
|
label == 'transphobic' ? '#f5d7d7' :
|
|
|
|
'#eeeeee';
|
2020-04-13 15:39:52 +02:00
|
|
|
confirmation.style.cssText = `transition: opacity 7s ease-in-out !important; opacity: 1; position: fixed; padding: 30px 15px; z-index: 99999999; white-space: pre-wrap; top: 200px; left: 30%; right: 30%; background: ${background}; color: black; font-weight: bold; font-family: Arial; box-shadow: 0px 5px 10px #ddd; border: 1px solid #ccc; font-size: 11pt;`;
|
2019-10-06 16:31:46 +02:00
|
|
|
let text: string;
|
|
|
|
|
|
|
|
if (label == 'bad-identifier') {
|
2020-04-13 09:39:05 +02:00
|
|
|
const displayReason = getBadIdentifierReason(identifier, url, target);
|
2019-10-06 16:31:46 +02:00
|
|
|
if (displayReason) text = displayReason;
|
|
|
|
else if (badIdentifierReason == 'SN') text = 'This social network is not supported: ' + identifier + '.';
|
|
|
|
else if (badIdentifierReason == 'AR') text = 'This is an archival link, it cannot be labeled: ' + identifier;
|
|
|
|
else text = `This item could not be labeled. Possible reasons:
|
|
|
|
• It doesn't represent a specific user or page
|
|
|
|
• It's not a kind of object supported by Shinigami Eyes
|
|
|
|
|
|
|
|
${identifier || url}
|
|
|
|
`;
|
|
|
|
} else {
|
|
|
|
text = identifier + (
|
|
|
|
label == 't-friendly' ? ' will be displayed as trans-friendly on search engines and social networks.' :
|
|
|
|
label == 'transphobic' ? ' will be displayed as anti-trans on search engines and social networks.' :
|
|
|
|
' has been cleared.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
confirmation.textContent = text;
|
2019-10-06 14:29:26 +02:00
|
|
|
document.body.appendChild(confirmation);
|
2019-10-06 16:31:46 +02:00
|
|
|
previousConfirmationMessage = confirmation;
|
|
|
|
confirmation.addEventListener('mousedown', () => confirmation.remove());
|
|
|
|
setTimeout(() => {
|
|
|
|
confirmation.style.opacity = '0';
|
|
|
|
}, 2000);
|
|
|
|
|
2019-10-06 14:29:26 +02:00
|
|
|
setTimeout(() => {
|
|
|
|
confirmation.remove();
|
2019-10-06 16:31:46 +02:00
|
|
|
}, 9000);
|
2019-10-06 14:29:26 +02:00
|
|
|
}
|
2018-12-16 16:42:20 +01:00
|
|
|
|
2019-06-29 19:47:05 +02:00
|
|
|
browser.runtime.onMessage.addListener<ShinigamiEyesMessage, ShinigamiEyesSubmission>((message, sender, sendResponse) => {
|
2019-03-03 21:02:40 +01:00
|
|
|
|
2019-10-06 16:31:46 +02:00
|
|
|
if (message.updateAllLabels || message.confirmSetLabel) {
|
2020-04-13 09:39:05 +02:00
|
|
|
displayConfirmation(message.confirmSetIdentifier, message.confirmSetLabel, message.badIdentifierReason, message.confirmSetUrl, null);
|
2019-03-03 21:02:40 +01:00
|
|
|
updateAllLabels(true);
|
|
|
|
return;
|
|
|
|
}
|
2019-06-29 19:54:25 +02:00
|
|
|
|
2019-03-03 21:02:40 +01:00
|
|
|
message.contextPage = window.location.href;
|
2020-04-13 10:19:27 +02:00
|
|
|
const originalTarget = lastRightClickedElement;
|
|
|
|
let target = originalTarget; // message.elementId ? browser.menus.getTargetElement(message.elementId) : null;
|
2019-06-29 19:54:25 +02:00
|
|
|
|
|
|
|
while (target) {
|
2020-04-13 10:05:46 +02:00
|
|
|
if (target instanceof HTMLAnchorElement) break;
|
2019-03-03 21:02:40 +01:00
|
|
|
target = target.parentElement;
|
|
|
|
}
|
|
|
|
|
2019-06-29 19:47:05 +02:00
|
|
|
if (target && (<HTMLAnchorElement>target).href != message.url) target = null;
|
2018-12-16 16:42:20 +01:00
|
|
|
|
2020-04-13 10:19:27 +02:00
|
|
|
var identifier = target ? getIdentifier(<HTMLAnchorElement>target, originalTarget) : getIdentifier(message.url);
|
2019-10-06 16:31:46 +02:00
|
|
|
if (!identifier) {
|
2020-04-13 09:39:05 +02:00
|
|
|
displayConfirmation(null, 'bad-identifier', null, message.url, target);
|
2019-10-06 16:31:46 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-03-03 21:02:40 +01:00
|
|
|
|
|
|
|
message.identifier = identifier;
|
|
|
|
if (identifier.startsWith('facebook.com/'))
|
|
|
|
message.secondaryIdentifier = getIdentifier(message.url);
|
2019-03-03 21:02:57 +01:00
|
|
|
|
2019-06-29 19:54:25 +02:00
|
|
|
var snippet = getSnippet(target);
|
2018-12-17 21:56:30 +01:00
|
|
|
message.linkId = ++lastGeneratedLinkId;
|
|
|
|
|
2019-06-29 19:54:25 +02:00
|
|
|
if (target)
|
2019-06-29 19:47:05 +02:00
|
|
|
target.setAttribute('shinigami-eyes-link-id', '' + lastGeneratedLinkId);
|
2018-12-17 21:56:30 +01:00
|
|
|
|
2019-03-03 21:02:40 +01:00
|
|
|
message.snippet = snippet ? snippet.outerHTML : null;
|
2018-12-16 17:36:19 +01:00
|
|
|
var debugClass = 'shinigami-eyes-debug-snippet-highlight';
|
2019-06-29 19:54:25 +02:00
|
|
|
|
2019-03-03 21:02:40 +01:00
|
|
|
if (snippet && message.debug) {
|
|
|
|
snippet.classList.add(debugClass);
|
2018-12-16 17:36:19 +01:00
|
|
|
if (message.debug <= 1)
|
2019-03-03 21:02:40 +01:00
|
|
|
setTimeout(() => snippet.classList.remove(debugClass), 1500)
|
2018-12-16 17:36:19 +01:00
|
|
|
}
|
2019-10-06 14:29:26 +02:00
|
|
|
message.isSocialNetwork = isSocialNetwork;
|
2018-09-16 12:27:42 +02:00
|
|
|
sendResponse(message);
|
|
|
|
})
|