Format code

This commit is contained in:
shinigami-eyes 2019-06-29 19:54:25 +02:00
parent da80996a8c
commit e66a79df0c
4 changed files with 55 additions and 55 deletions

View File

@ -1,4 +1,4 @@
var browser : Browser = browser || chrome;
var browser: Browser = browser || chrome;
const PENDING_SUBMISSIONS = ':PENDING_SUBMISSIONS'
const MIGRATION = ':MIGRATION'
@ -232,24 +232,24 @@ const badIdentifiersArray = [
'youtube.com/redirect',
'youtube.com/watch',
];
const badIdentifiers : {[id: string]: true} = {};
const badIdentifiers: { [id: string]: true } = {};
badIdentifiersArray.forEach(x => badIdentifiers[x] = true);
var lastSubmissionError : string = null;
var lastSubmissionError: string = null;
const needsInfiniteResubmissionWorkaround = [
'046775268347','094745034139','059025030493','016970595453','016488055088','028573603939',
'047702135398','035965787127','069722626647','044482561296','068530257405','071378971311',
'050784255720','074169481269','001621982155','014636303566','016313013148','051923868290',
'025348057349','059525793150','047081840457','086106188740','080095076304','059341889183',
'095799487873','099003666813','002434495335','009844923475','034297166260','065739632127',
'040689448048','048816243838','018152001078','059285890303','073205501344','096068619182'
'046775268347', '094745034139', '059025030493', '016970595453', '016488055088', '028573603939',
'047702135398', '035965787127', '069722626647', '044482561296', '068530257405', '071378971311',
'050784255720', '074169481269', '001621982155', '014636303566', '016313013148', '051923868290',
'025348057349', '059525793150', '047081840457', '086106188740', '080095076304', '059341889183',
'095799487873', '099003666813', '002434495335', '009844923475', '034297166260', '065739632127',
'040689448048', '048816243838', '018152001078', '059285890303', '073205501344', '096068619182'
]
var overrides : LabelMap = null;
var overrides: LabelMap = null;
var accepted = false;
var installationId : string = null;
var installationId: string = null;
browser.storage.local.get(['overrides', 'accepted', 'installationId'], v => {
if (!v.installationId) {
@ -263,21 +263,21 @@ browser.storage.local.get(['overrides', 'accepted', 'installationId'], v => {
overrides = v.overrides || {}
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('facebook.com/a.')){
if (key.startsWith('facebook.com/a.')) {
delete overrides[key];
continue;
}
if (key != key.toLowerCase()){
if (key != key.toLowerCase()) {
let v = overrides[key];
delete overrides[key];
overrides[key.toLowerCase()] = v;
}
}
badIdentifiersArray.forEach(x => delete overrides[x]);
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) {
@ -313,7 +313,7 @@ browser.runtime.onMessage.addListener<ShinigamiEyesMessage, ShinigamiEyesMessage
uncommittedResponse = null;
return;
}
const response : LabelMap = {};
const response: LabelMap = {};
const transphobic = message.myself && bloomFilters.filter(x => x.name == 'transphobic')[0].test(message.myself);
for (const id of message.ids) {
if (overrides[id] !== undefined) {
@ -367,7 +367,7 @@ createContextMenu('Mark as t-friendly', 'mark-t-friendly');
createContextMenu('Clear', 'mark-none');
createContextMenu('Help', 'help');
var uncommittedResponse : ShinigamiEyesSubmission = null;
var uncommittedResponse: ShinigamiEyesSubmission = null;
async function submitPendingRatings() {
const submitted = getPendingSubmissions().map(x => x);
@ -385,19 +385,19 @@ async function submitPendingRatings() {
credentials: 'omit',
});
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);
overrides[PENDING_SUBMISSIONS] = <any>getPendingSubmissions().filter(x => submitted.indexOf(x) == -1);
browser.storage.local.set({ overrides: overrides });
} catch(e) {
} catch (e) {
lastSubmissionError = '' + e
}
}
function getPendingSubmissions() : ShinigamiEyesSubmission[]{
function getPendingSubmissions(): ShinigamiEyesSubmission[] {
return <any>overrides[PENDING_SUBMISSIONS];
}
@ -453,7 +453,7 @@ browser.contextMenus.onClicked.addListener(function (info, tab) {
debug: <any>overrides.debug
}, { frameId: frameId }, response => {
if (!response.identifier) return;
if (response.mark){
if (response.mark) {
if (badIdentifiers[response.identifier]) return;
if (response.secondaryIdentifier && badIdentifiers[response.secondaryIdentifier])
response.secondaryIdentifier = null;

View File

@ -1,4 +1,4 @@
var browser : Browser = browser || chrome;
var browser: Browser = browser || chrome;
var hostname = typeof (location) != 'undefined' ? location.hostname : '';
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('.youtube.com')) hostname = 'youtube.com';
var myself : string = null;
var myself: string = null;
function fixupSiteStyles() {
if (hostname == 'facebook.com') {
@ -29,7 +29,7 @@ function fixupSiteStyles() {
.assigned-label-transphobic { outline: 2px solid #991515 !important; }
.assigned-label-t-friendly { outline: 1px solid #77B91E !important; }
`);
} else if (hostname.indexOf('wiki') != -1){
} else if (hostname.indexOf('wiki') != -1) {
addStyleSheet(`
.assigned-label-transphobic { outline: 1px solid #991515 !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');
style.textContent = css;
document.head.appendChild(style);
}
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');
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_');
@ -122,9 +122,9 @@ function init() {
}, true);
}
var lastRightClickedElement : HTMLElement = null;
var lastAppliedYouTubeUrl : string = null;
var lastAppliedYouTubeTitle : string = null;
var lastRightClickedElement: HTMLElement = null;
var lastAppliedYouTubeUrl: string = null;
var lastAppliedYouTubeTitle: string = null;
function updateYouTubeChannelHeader() {
var url = window.location.href;
@ -168,7 +168,7 @@ function updateAllLabels(refresh?: boolean) {
var knownLabels: LabelMap = {};
var labelsToSolve : LabelToSolve[] = [];
var labelsToSolve: LabelToSolve[] = [];
function solvePendingLabels() {
if (!labelsToSolve.length) return;
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) {
var identifier = getIdentifier(a);
if (!identifier){
if(hostname == 'youtube.com')
if (!identifier) {
if (hostname == 'youtube.com')
applyLabel(a, '');
return;
}
@ -296,7 +296,7 @@ function getIdentifierFromElementImpl(element: HTMLAnchorElement): string {
// comment timestamp
if (element.firstChild && (<HTMLElement>element.firstChild).tagName == 'ABBR' && element.lastChild == element.firstChild) return null;
// post 'see more'
if (element.classList.contains('see_more_link')) return null;
@ -314,7 +314,7 @@ function getIdentifierFromElementImpl(element: HTMLAnchorElement): string {
// post Comments link
if (dataset.testid == 'UFI2CommentsCount/root') return null;
// post Comments link
if (dataset.commentPreludeRef) return null;
@ -348,23 +348,23 @@ function getIdentifierFromElementImpl(element: HTMLAnchorElement): string {
}
if (dataset && dataset.expandedUrl) return getIdentifierFromURLImpl(tryParseURL(dataset.expandedUrl));
const href = element.href;
if(href && !href.endsWith('#')) return getIdentifierFromURLImpl(tryParseURL(href));
if (href && !href.endsWith('#')) return getIdentifierFromURLImpl(tryParseURL(href));
return null;
}
function tryParseURL(urlstr: string){
function tryParseURL(urlstr: string) {
if (!urlstr) return null;
try {
const url = new URL(urlstr);
if (url.protocol != 'http:' && url.protocol != 'https:') return null;
return url;
} catch(e) {
} catch (e) {
return null;
}
}
function getIdentifierFromURLImpl(url: URL): string{
if(!url) return null;
function getIdentifierFromURLImpl(url: URL): string {
if (!url) return null;
// nested urls
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)));
if(newurl) return getIdentifierFromURLImpl(newurl);
if (newurl) return getIdentifierFromURLImpl(newurl);
}
// fb group member badge
@ -405,7 +405,7 @@ function getIdentifierFromURLImpl(url: URL): string{
} else if (domainIs(host, 'reddit.com')) {
const pathname = url.pathname.replace('/u/', '/user/');
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);
} else if (domainIs(host, 'twitter.com')) {
return 'twitter.com' + getPartialPath(url.pathname, 1);
@ -445,7 +445,7 @@ init();
var lastGeneratedLinkId = 0;
function getSnippet(node: HTMLElement){
function getSnippet(node: HTMLElement) {
while (node) {
var classList = node.classList;
if (hostname == 'facebook.com' && node.dataset && node.dataset.ftr) return node;
@ -468,12 +468,12 @@ browser.runtime.onMessage.addListener<ShinigamiEyesMessage, ShinigamiEyesSubmiss
updateAllLabels(true);
return;
}
message.contextPage = window.location.href;
var target = lastRightClickedElement; // message.elementId ? browser.menus.getTargetElement(message.elementId) : null;
while(target){
if((<HTMLAnchorElement>target).href) break;
while (target) {
if ((<HTMLAnchorElement>target).href) break;
target = target.parentElement;
}
@ -486,15 +486,15 @@ browser.runtime.onMessage.addListener<ShinigamiEyesMessage, ShinigamiEyesSubmiss
if (identifier.startsWith('facebook.com/'))
message.secondaryIdentifier = getIdentifier(message.url);
var snippet = getSnippet(target);
var snippet = getSnippet(target);
message.linkId = ++lastGeneratedLinkId;
if (target)
if (target)
target.setAttribute('shinigami-eyes-link-id', '' + lastGeneratedLinkId);
message.snippet = snippet ? snippet.outerHTML : null;
var debugClass = 'shinigami-eyes-debug-snippet-highlight';
if (snippet && message.debug) {
snippet.classList.add(debugClass);
if (message.debug <= 1)

View File

@ -31,9 +31,9 @@ interface ShinigamiEyesCommand {
ids?: string[]
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';

View File

@ -1,4 +1,4 @@
var browser : Browser = browser || chrome;
var browser: Browser = browser || chrome;
document.getElementById('cancelButton').addEventListener('click', () => {
browser.runtime.sendMessage({ acceptClicked: false }, () => { });