Format code
This commit is contained in:
parent
da80996a8c
commit
e66a79df0c
@ -1,4 +1,4 @@
|
|||||||
var browser : Browser = browser || chrome;
|
var browser: Browser = browser || chrome;
|
||||||
|
|
||||||
const PENDING_SUBMISSIONS = ':PENDING_SUBMISSIONS'
|
const PENDING_SUBMISSIONS = ':PENDING_SUBMISSIONS'
|
||||||
const MIGRATION = ':MIGRATION'
|
const MIGRATION = ':MIGRATION'
|
||||||
@ -232,24 +232,24 @@ const badIdentifiersArray = [
|
|||||||
'youtube.com/redirect',
|
'youtube.com/redirect',
|
||||||
'youtube.com/watch',
|
'youtube.com/watch',
|
||||||
];
|
];
|
||||||
const badIdentifiers : {[id: string]: true} = {};
|
const badIdentifiers: { [id: string]: true } = {};
|
||||||
badIdentifiersArray.forEach(x => badIdentifiers[x] = true);
|
badIdentifiersArray.forEach(x => badIdentifiers[x] = true);
|
||||||
|
|
||||||
var lastSubmissionError : string = null;
|
var lastSubmissionError: string = null;
|
||||||
|
|
||||||
const needsInfiniteResubmissionWorkaround = [
|
const needsInfiniteResubmissionWorkaround = [
|
||||||
'046775268347','094745034139','059025030493','016970595453','016488055088','028573603939',
|
'046775268347', '094745034139', '059025030493', '016970595453', '016488055088', '028573603939',
|
||||||
'047702135398','035965787127','069722626647','044482561296','068530257405','071378971311',
|
'047702135398', '035965787127', '069722626647', '044482561296', '068530257405', '071378971311',
|
||||||
'050784255720','074169481269','001621982155','014636303566','016313013148','051923868290',
|
'050784255720', '074169481269', '001621982155', '014636303566', '016313013148', '051923868290',
|
||||||
'025348057349','059525793150','047081840457','086106188740','080095076304','059341889183',
|
'025348057349', '059525793150', '047081840457', '086106188740', '080095076304', '059341889183',
|
||||||
'095799487873','099003666813','002434495335','009844923475','034297166260','065739632127',
|
'095799487873', '099003666813', '002434495335', '009844923475', '034297166260', '065739632127',
|
||||||
'040689448048','048816243838','018152001078','059285890303','073205501344','096068619182'
|
'040689448048', '048816243838', '018152001078', '059285890303', '073205501344', '096068619182'
|
||||||
]
|
]
|
||||||
|
|
||||||
var overrides : LabelMap = null;
|
var overrides: LabelMap = null;
|
||||||
|
|
||||||
var accepted = false;
|
var accepted = false;
|
||||||
var installationId : string = null;
|
var installationId: string = null;
|
||||||
|
|
||||||
browser.storage.local.get(['overrides', 'accepted', 'installationId'], v => {
|
browser.storage.local.get(['overrides', 'accepted', 'installationId'], v => {
|
||||||
if (!v.installationId) {
|
if (!v.installationId) {
|
||||||
@ -263,21 +263,21 @@ browser.storage.local.get(['overrides', 'accepted', 'installationId'], v => {
|
|||||||
overrides = v.overrides || {}
|
overrides = v.overrides || {}
|
||||||
|
|
||||||
const migration = overrides[MIGRATION] || 0;
|
const migration = overrides[MIGRATION] || 0;
|
||||||
if (migration < CURRENT_VERSION){
|
if (migration < CURRENT_VERSION) {
|
||||||
|
|
||||||
for (const key of Object.getOwnPropertyNames(overrides)){
|
for (const key of Object.getOwnPropertyNames(overrides)) {
|
||||||
if (key.startsWith(':')) continue;
|
if (key.startsWith(':')) continue;
|
||||||
if (key.startsWith('facebook.com/a.')){
|
if (key.startsWith('facebook.com/a.')) {
|
||||||
delete overrides[key];
|
delete overrides[key];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (key != key.toLowerCase()){
|
if (key != key.toLowerCase()) {
|
||||||
let v = overrides[key];
|
let v = overrides[key];
|
||||||
delete overrides[key];
|
delete overrides[key];
|
||||||
overrides[key.toLowerCase()] = v;
|
overrides[key.toLowerCase()] = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
badIdentifiersArray.forEach(x => delete overrides[x]);
|
badIdentifiersArray.forEach(x => delete overrides[x]);
|
||||||
|
|
||||||
if (needsInfiniteResubmissionWorkaround.indexOf(installationId.substring(0, 12)) != -1)
|
if (needsInfiniteResubmissionWorkaround.indexOf(installationId.substring(0, 12)) != -1)
|
||||||
@ -287,7 +287,7 @@ browser.storage.local.get(['overrides', 'accepted', 'installationId'], v => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const bloomFilters : BloomFilter[] = [];
|
const bloomFilters: BloomFilter[] = [];
|
||||||
|
|
||||||
async function loadBloomFilter(name: LabelKind) {
|
async function loadBloomFilter(name: LabelKind) {
|
||||||
|
|
||||||
@ -313,7 +313,7 @@ browser.runtime.onMessage.addListener<ShinigamiEyesMessage, ShinigamiEyesMessage
|
|||||||
uncommittedResponse = null;
|
uncommittedResponse = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response : LabelMap = {};
|
const response: LabelMap = {};
|
||||||
const transphobic = message.myself && bloomFilters.filter(x => x.name == 'transphobic')[0].test(message.myself);
|
const transphobic = message.myself && bloomFilters.filter(x => x.name == 'transphobic')[0].test(message.myself);
|
||||||
for (const id of message.ids) {
|
for (const id of message.ids) {
|
||||||
if (overrides[id] !== undefined) {
|
if (overrides[id] !== undefined) {
|
||||||
@ -367,7 +367,7 @@ createContextMenu('Mark as t-friendly', 'mark-t-friendly');
|
|||||||
createContextMenu('Clear', 'mark-none');
|
createContextMenu('Clear', 'mark-none');
|
||||||
createContextMenu('Help', 'help');
|
createContextMenu('Help', 'help');
|
||||||
|
|
||||||
var uncommittedResponse : ShinigamiEyesSubmission = null;
|
var uncommittedResponse: ShinigamiEyesSubmission = null;
|
||||||
|
|
||||||
async function submitPendingRatings() {
|
async function submitPendingRatings() {
|
||||||
const submitted = getPendingSubmissions().map(x => x);
|
const submitted = getPendingSubmissions().map(x => x);
|
||||||
@ -385,19 +385,19 @@ async function submitPendingRatings() {
|
|||||||
credentials: 'omit',
|
credentials: 'omit',
|
||||||
});
|
});
|
||||||
if (response.status != 200) throw ('HTTP status: ' + response.status)
|
if (response.status != 200) throw ('HTTP status: ' + response.status)
|
||||||
const result = await response.text();
|
const result = await response.text();
|
||||||
|
|
||||||
if (result != 'SUCCESS') throw 'Bad response: ' + ('' + result).substring(0, 20);
|
if (result != 'SUCCESS') throw 'Bad response: ' + ('' + result).substring(0, 20);
|
||||||
|
|
||||||
overrides[PENDING_SUBMISSIONS] = <any>getPendingSubmissions().filter(x => submitted.indexOf(x) == -1);
|
overrides[PENDING_SUBMISSIONS] = <any>getPendingSubmissions().filter(x => submitted.indexOf(x) == -1);
|
||||||
browser.storage.local.set({ overrides: overrides });
|
browser.storage.local.set({ overrides: overrides });
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
lastSubmissionError = '' + e
|
lastSubmissionError = '' + e
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPendingSubmissions() : ShinigamiEyesSubmission[]{
|
function getPendingSubmissions(): ShinigamiEyesSubmission[] {
|
||||||
return <any>overrides[PENDING_SUBMISSIONS];
|
return <any>overrides[PENDING_SUBMISSIONS];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -453,7 +453,7 @@ browser.contextMenus.onClicked.addListener(function (info, tab) {
|
|||||||
debug: <any>overrides.debug
|
debug: <any>overrides.debug
|
||||||
}, { frameId: frameId }, response => {
|
}, { frameId: frameId }, response => {
|
||||||
if (!response.identifier) return;
|
if (!response.identifier) return;
|
||||||
if (response.mark){
|
if (response.mark) {
|
||||||
if (badIdentifiers[response.identifier]) return;
|
if (badIdentifiers[response.identifier]) return;
|
||||||
if (response.secondaryIdentifier && badIdentifiers[response.secondaryIdentifier])
|
if (response.secondaryIdentifier && badIdentifiers[response.secondaryIdentifier])
|
||||||
response.secondaryIdentifier = null;
|
response.secondaryIdentifier = null;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
var browser : Browser = browser || chrome;
|
var browser: Browser = browser || chrome;
|
||||||
|
|
||||||
var hostname = typeof (location) != 'undefined' ? location.hostname : '';
|
var hostname = typeof (location) != 'undefined' ? location.hostname : '';
|
||||||
if (hostname.startsWith('www.')) {
|
if (hostname.startsWith('www.')) {
|
||||||
@ -8,7 +8,7 @@ if (hostname.endsWith('.reddit.com')) hostname = 'reddit.com';
|
|||||||
if (hostname.endsWith('.facebook.com')) hostname = 'facebook.com';
|
if (hostname.endsWith('.facebook.com')) hostname = 'facebook.com';
|
||||||
if (hostname.endsWith('.youtube.com')) hostname = 'youtube.com';
|
if (hostname.endsWith('.youtube.com')) hostname = 'youtube.com';
|
||||||
|
|
||||||
var myself : string = null;
|
var myself: string = null;
|
||||||
|
|
||||||
function fixupSiteStyles() {
|
function fixupSiteStyles() {
|
||||||
if (hostname == 'facebook.com') {
|
if (hostname == 'facebook.com') {
|
||||||
@ -29,7 +29,7 @@ function fixupSiteStyles() {
|
|||||||
.assigned-label-transphobic { outline: 2px solid #991515 !important; }
|
.assigned-label-transphobic { outline: 2px solid #991515 !important; }
|
||||||
.assigned-label-t-friendly { outline: 1px solid #77B91E !important; }
|
.assigned-label-t-friendly { outline: 1px solid #77B91E !important; }
|
||||||
`);
|
`);
|
||||||
} else if (hostname.indexOf('wiki') != -1){
|
} else if (hostname.indexOf('wiki') != -1) {
|
||||||
addStyleSheet(`
|
addStyleSheet(`
|
||||||
.assigned-label-transphobic { outline: 1px solid #991515 !important; }
|
.assigned-label-transphobic { outline: 1px solid #991515 !important; }
|
||||||
.assigned-label-t-friendly { outline: 1px solid #77B91E !important; }
|
.assigned-label-t-friendly { outline: 1px solid #77B91E !important; }
|
||||||
@ -64,14 +64,14 @@ function fixupSiteStyles() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addStyleSheet(css: string){
|
function addStyleSheet(css: string) {
|
||||||
const style = document.createElement('style');
|
const style = document.createElement('style');
|
||||||
style.textContent = css;
|
style.textContent = css;
|
||||||
document.head.appendChild(style);
|
document.head.appendChild(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
function maybeDisableCustomCss() {
|
function maybeDisableCustomCss() {
|
||||||
var shouldDisable: (s: {ownerNode: HTMLElement}) => boolean = null;
|
var shouldDisable: (s: { ownerNode: HTMLElement }) => boolean = null;
|
||||||
if (hostname == 'twitter.com') shouldDisable = x => x.ownerNode && x.ownerNode.id && x.ownerNode.id.startsWith('user-style');
|
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 == '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_');
|
else if (hostname == 'disqus.com') shouldDisable = x => x.ownerNode && x.ownerNode.id && x.ownerNode.id.startsWith('css_');
|
||||||
@ -122,9 +122,9 @@ function init() {
|
|||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
var lastRightClickedElement : HTMLElement = null;
|
var lastRightClickedElement: HTMLElement = null;
|
||||||
var lastAppliedYouTubeUrl : string = null;
|
var lastAppliedYouTubeUrl: string = null;
|
||||||
var lastAppliedYouTubeTitle : string = null;
|
var lastAppliedYouTubeTitle: string = null;
|
||||||
|
|
||||||
function updateYouTubeChannelHeader() {
|
function updateYouTubeChannelHeader() {
|
||||||
var url = window.location.href;
|
var url = window.location.href;
|
||||||
@ -168,7 +168,7 @@ function updateAllLabels(refresh?: boolean) {
|
|||||||
|
|
||||||
var knownLabels: LabelMap = {};
|
var knownLabels: LabelMap = {};
|
||||||
|
|
||||||
var labelsToSolve : LabelToSolve[] = [];
|
var labelsToSolve: LabelToSolve[] = [];
|
||||||
function solvePendingLabels() {
|
function solvePendingLabels() {
|
||||||
if (!labelsToSolve.length) return;
|
if (!labelsToSolve.length) return;
|
||||||
var uniqueIdentifiers = Array.from(new Set(labelsToSolve.map(x => x.identifier)));
|
var uniqueIdentifiers = Array.from(new Set(labelsToSolve.map(x => x.identifier)));
|
||||||
@ -201,8 +201,8 @@ function applyLabel(a: HTMLAnchorElement, identifier: string) {
|
|||||||
|
|
||||||
function initLink(a: HTMLAnchorElement) {
|
function initLink(a: HTMLAnchorElement) {
|
||||||
var identifier = getIdentifier(a);
|
var identifier = getIdentifier(a);
|
||||||
if (!identifier){
|
if (!identifier) {
|
||||||
if(hostname == 'youtube.com')
|
if (hostname == 'youtube.com')
|
||||||
applyLabel(a, '');
|
applyLabel(a, '');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -296,7 +296,7 @@ function getIdentifierFromElementImpl(element: HTMLAnchorElement): string {
|
|||||||
|
|
||||||
// comment timestamp
|
// comment timestamp
|
||||||
if (element.firstChild && (<HTMLElement>element.firstChild).tagName == 'ABBR' && element.lastChild == element.firstChild) return null;
|
if (element.firstChild && (<HTMLElement>element.firstChild).tagName == 'ABBR' && element.lastChild == element.firstChild) return null;
|
||||||
|
|
||||||
// post 'see more'
|
// post 'see more'
|
||||||
if (element.classList.contains('see_more_link')) return null;
|
if (element.classList.contains('see_more_link')) return null;
|
||||||
|
|
||||||
@ -314,7 +314,7 @@ function getIdentifierFromElementImpl(element: HTMLAnchorElement): string {
|
|||||||
|
|
||||||
// post Comments link
|
// post Comments link
|
||||||
if (dataset.testid == 'UFI2CommentsCount/root') return null;
|
if (dataset.testid == 'UFI2CommentsCount/root') return null;
|
||||||
|
|
||||||
// post Comments link
|
// post Comments link
|
||||||
if (dataset.commentPreludeRef) return null;
|
if (dataset.commentPreludeRef) return null;
|
||||||
|
|
||||||
@ -348,23 +348,23 @@ function getIdentifierFromElementImpl(element: HTMLAnchorElement): string {
|
|||||||
}
|
}
|
||||||
if (dataset && dataset.expandedUrl) return getIdentifierFromURLImpl(tryParseURL(dataset.expandedUrl));
|
if (dataset && dataset.expandedUrl) return getIdentifierFromURLImpl(tryParseURL(dataset.expandedUrl));
|
||||||
const href = element.href;
|
const href = element.href;
|
||||||
if(href && !href.endsWith('#')) return getIdentifierFromURLImpl(tryParseURL(href));
|
if (href && !href.endsWith('#')) return getIdentifierFromURLImpl(tryParseURL(href));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function tryParseURL(urlstr: string){
|
function tryParseURL(urlstr: string) {
|
||||||
if (!urlstr) return null;
|
if (!urlstr) return null;
|
||||||
try {
|
try {
|
||||||
const url = new URL(urlstr);
|
const url = new URL(urlstr);
|
||||||
if (url.protocol != 'http:' && url.protocol != 'https:') return null;
|
if (url.protocol != 'http:' && url.protocol != 'https:') return null;
|
||||||
return url;
|
return url;
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getIdentifierFromURLImpl(url: URL): string{
|
function getIdentifierFromURLImpl(url: URL): string {
|
||||||
if(!url) return null;
|
if (!url) return null;
|
||||||
|
|
||||||
// nested urls
|
// nested urls
|
||||||
if (url.href.indexOf('http', 1) != -1) {
|
if (url.href.indexOf('http', 1) != -1) {
|
||||||
@ -383,7 +383,7 @@ function getIdentifierFromURLImpl(url: URL): string{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const newurl = tryParseURL(url.href.substring(url.href.indexOf('http', 1)));
|
const newurl = tryParseURL(url.href.substring(url.href.indexOf('http', 1)));
|
||||||
if(newurl) return getIdentifierFromURLImpl(newurl);
|
if (newurl) return getIdentifierFromURLImpl(newurl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// fb group member badge
|
// fb group member badge
|
||||||
@ -405,7 +405,7 @@ function getIdentifierFromURLImpl(url: URL): string{
|
|||||||
} else if (domainIs(host, 'reddit.com')) {
|
} else if (domainIs(host, 'reddit.com')) {
|
||||||
const pathname = url.pathname.replace('/u/', '/user/');
|
const pathname = url.pathname.replace('/u/', '/user/');
|
||||||
if (!pathname.startsWith('/user/') && !pathname.startsWith('/r/')) return null;
|
if (!pathname.startsWith('/user/') && !pathname.startsWith('/r/')) return null;
|
||||||
if(pathname.includes('/comments/') && hostname == 'reddit.com') return null;
|
if (pathname.includes('/comments/') && hostname == 'reddit.com') return null;
|
||||||
return 'reddit.com' + getPartialPath(pathname, 2);
|
return 'reddit.com' + getPartialPath(pathname, 2);
|
||||||
} else if (domainIs(host, 'twitter.com')) {
|
} else if (domainIs(host, 'twitter.com')) {
|
||||||
return 'twitter.com' + getPartialPath(url.pathname, 1);
|
return 'twitter.com' + getPartialPath(url.pathname, 1);
|
||||||
@ -445,7 +445,7 @@ init();
|
|||||||
|
|
||||||
var lastGeneratedLinkId = 0;
|
var lastGeneratedLinkId = 0;
|
||||||
|
|
||||||
function getSnippet(node: HTMLElement){
|
function getSnippet(node: HTMLElement) {
|
||||||
while (node) {
|
while (node) {
|
||||||
var classList = node.classList;
|
var classList = node.classList;
|
||||||
if (hostname == 'facebook.com' && node.dataset && node.dataset.ftr) return node;
|
if (hostname == 'facebook.com' && node.dataset && node.dataset.ftr) return node;
|
||||||
@ -468,12 +468,12 @@ browser.runtime.onMessage.addListener<ShinigamiEyesMessage, ShinigamiEyesSubmiss
|
|||||||
updateAllLabels(true);
|
updateAllLabels(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
message.contextPage = window.location.href;
|
message.contextPage = window.location.href;
|
||||||
var target = lastRightClickedElement; // message.elementId ? browser.menus.getTargetElement(message.elementId) : null;
|
var target = lastRightClickedElement; // message.elementId ? browser.menus.getTargetElement(message.elementId) : null;
|
||||||
|
|
||||||
while(target){
|
while (target) {
|
||||||
if((<HTMLAnchorElement>target).href) break;
|
if ((<HTMLAnchorElement>target).href) break;
|
||||||
target = target.parentElement;
|
target = target.parentElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -486,15 +486,15 @@ browser.runtime.onMessage.addListener<ShinigamiEyesMessage, ShinigamiEyesSubmiss
|
|||||||
if (identifier.startsWith('facebook.com/'))
|
if (identifier.startsWith('facebook.com/'))
|
||||||
message.secondaryIdentifier = getIdentifier(message.url);
|
message.secondaryIdentifier = getIdentifier(message.url);
|
||||||
|
|
||||||
var snippet = getSnippet(target);
|
var snippet = getSnippet(target);
|
||||||
message.linkId = ++lastGeneratedLinkId;
|
message.linkId = ++lastGeneratedLinkId;
|
||||||
|
|
||||||
if (target)
|
if (target)
|
||||||
target.setAttribute('shinigami-eyes-link-id', '' + lastGeneratedLinkId);
|
target.setAttribute('shinigami-eyes-link-id', '' + lastGeneratedLinkId);
|
||||||
|
|
||||||
message.snippet = snippet ? snippet.outerHTML : null;
|
message.snippet = snippet ? snippet.outerHTML : null;
|
||||||
var debugClass = 'shinigami-eyes-debug-snippet-highlight';
|
var debugClass = 'shinigami-eyes-debug-snippet-highlight';
|
||||||
|
|
||||||
if (snippet && message.debug) {
|
if (snippet && message.debug) {
|
||||||
snippet.classList.add(debugClass);
|
snippet.classList.add(debugClass);
|
||||||
if (message.debug <= 1)
|
if (message.debug <= 1)
|
||||||
|
4
extension/definitions.d.ts
vendored
4
extension/definitions.d.ts
vendored
@ -31,9 +31,9 @@ interface ShinigamiEyesCommand {
|
|||||||
ids?: string[]
|
ids?: string[]
|
||||||
updateAllLabels?: boolean
|
updateAllLabels?: boolean
|
||||||
}
|
}
|
||||||
type LabelMap = {[identifier: string]: LabelKind};
|
type LabelMap = { [identifier: string]: LabelKind };
|
||||||
|
|
||||||
interface ShinigamiEyesMessage extends ShinigamiEyesSubmission, ShinigamiEyesCommand{
|
interface ShinigamiEyesMessage extends ShinigamiEyesSubmission, ShinigamiEyesCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ContextMenuCommand = 'mark-t-friendly' | 'mark-transphobic' | 'mark-none' | 'help';
|
type ContextMenuCommand = 'mark-t-friendly' | 'mark-transphobic' | 'mark-none' | 'help';
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
var browser : Browser = browser || chrome;
|
var browser: Browser = browser || chrome;
|
||||||
|
|
||||||
document.getElementById('cancelButton').addEventListener('click', () => {
|
document.getElementById('cancelButton').addEventListener('click', () => {
|
||||||
browser.runtime.sendMessage({ acceptClicked: false }, () => { });
|
browser.runtime.sendMessage({ acceptClicked: false }, () => { });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user