Format code
This commit is contained in:
parent
6732442911
commit
f01e53e0e3
@ -8,10 +8,10 @@ var installationId = null;
|
|||||||
browser.storage.local.get(['overrides', 'accepted', 'installationId'], v => {
|
browser.storage.local.get(['overrides', 'accepted', 'installationId'], v => {
|
||||||
accepted = v.accepted
|
accepted = v.accepted
|
||||||
overrides = v.overrides || {}
|
overrides = v.overrides || {}
|
||||||
if(!v.installationId){
|
if (!v.installationId) {
|
||||||
installationId = (Math.random()+ '.' +Math.random() + '.' +Math.random()).replace(/\./g, '');
|
installationId = (Math.random() + '.' + Math.random() + '.' + Math.random()).replace(/\./g, '');
|
||||||
browser.storage.local.set({installationId: installationId});
|
browser.storage.local.set({ installationId: installationId });
|
||||||
}else{
|
} else {
|
||||||
installationId = v.installationId;
|
installationId = v.installationId;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -34,11 +34,11 @@ function loadBloomFilter(name) {
|
|||||||
|
|
||||||
|
|
||||||
browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||||
if(message.acceptClicked !== undefined) {
|
if (message.acceptClicked !== undefined) {
|
||||||
accepted = message.acceptClicked;
|
accepted = message.acceptClicked;
|
||||||
browser.storage.local.set({accepted: accepted});
|
browser.storage.local.set({ accepted: accepted });
|
||||||
browser.tabs.remove(sender.tab.id);
|
browser.tabs.remove(sender.tab.id);
|
||||||
if(accepted && uncommittedResponse)
|
if (accepted && uncommittedResponse)
|
||||||
saveLabel(uncommittedResponse)
|
saveLabel(uncommittedResponse)
|
||||||
uncommittedResponse = null;
|
uncommittedResponse = null;
|
||||||
return;
|
return;
|
||||||
@ -53,10 +53,10 @@ browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
|||||||
if (transphobic) {
|
if (transphobic) {
|
||||||
if (id == message.myself) continue;
|
if (id == message.myself) continue;
|
||||||
var sum = 0;
|
var sum = 0;
|
||||||
for(var i = 0; i < id.length; i++){
|
for (var i = 0; i < id.length; i++) {
|
||||||
sum += id.charCodeAt(i);
|
sum += id.charCodeAt(i);
|
||||||
}
|
}
|
||||||
if(sum % 8 != 0) continue;
|
if (sum % 8 != 0) continue;
|
||||||
}
|
}
|
||||||
for (var bloomFilter of bloomFilters) {
|
for (var bloomFilter of bloomFilters) {
|
||||||
if (bloomFilter.test(id)) response[id] = bloomFilter.name;
|
if (bloomFilter.test(id)) response[id] = bloomFilter.name;
|
||||||
@ -94,40 +94,40 @@ createContextMenu('Help', 'help');
|
|||||||
|
|
||||||
var uncommittedResponse = null;
|
var uncommittedResponse = null;
|
||||||
|
|
||||||
function submitPendingRatings(){
|
function submitPendingRatings() {
|
||||||
var submitted = overrides[PENDING_SUBMISSIONS].map(x => x);
|
var submitted = overrides[PENDING_SUBMISSIONS].map(x => x);
|
||||||
var requestBody ={
|
var requestBody = {
|
||||||
installationId: installationId,
|
installationId: installationId,
|
||||||
entries: submitted
|
entries: submitted
|
||||||
}
|
}
|
||||||
console.log('Sending request');
|
console.log('Sending request');
|
||||||
fetch('https://shinigami-eyes.azurewebsites.net/api/submit', {
|
fetch('https://shinigami-eyes.azurewebsites.net/api/submit', {
|
||||||
body: JSON.stringify(requestBody),
|
body: JSON.stringify(requestBody),
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
credentials: 'omit',
|
credentials: 'omit',
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
response.text().then(result => {
|
response.text().then(result => {
|
||||||
console.log('Response: ' + result);
|
console.log('Response: ' + result);
|
||||||
if(result == 'SUCCESS'){
|
if (result == 'SUCCESS') {
|
||||||
overrides[PENDING_SUBMISSIONS] = overrides[PENDING_SUBMISSIONS].filter(x => submitted.indexOf(x) == -1);
|
overrides[PENDING_SUBMISSIONS] = overrides[PENDING_SUBMISSIONS].filter(x => submitted.indexOf(x) == -1);
|
||||||
browser.storage.local.set({overrides: overrides});
|
browser.storage.local.set({ overrides: overrides });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var PENDING_SUBMISSIONS = ':PENDING_SUBMISSIONS'
|
var PENDING_SUBMISSIONS = ':PENDING_SUBMISSIONS'
|
||||||
|
|
||||||
function saveLabel(response){
|
function saveLabel(response) {
|
||||||
if(accepted){
|
if (accepted) {
|
||||||
if(!overrides[PENDING_SUBMISSIONS]){
|
if (!overrides[PENDING_SUBMISSIONS]) {
|
||||||
overrides[PENDING_SUBMISSIONS] = Object.getOwnPropertyNames(overrides)
|
overrides[PENDING_SUBMISSIONS] = Object.getOwnPropertyNames(overrides)
|
||||||
.map(x => { return { identifier: x, label: overrides[x] }});
|
.map(x => { return { identifier: x, label: overrides[x] } });
|
||||||
}
|
}
|
||||||
overrides[response.identifier] = response.mark;
|
overrides[response.identifier] = response.mark;
|
||||||
browser.storage.local.set({overrides: overrides});
|
browser.storage.local.set({ overrides: overrides });
|
||||||
overrides[PENDING_SUBMISSIONS].push(response);
|
overrides[PENDING_SUBMISSIONS].push(response);
|
||||||
submitPendingRatings();
|
submitPendingRatings();
|
||||||
//console.log(response);
|
//console.log(response);
|
||||||
@ -139,20 +139,20 @@ function saveLabel(response){
|
|||||||
openHelp();
|
openHelp();
|
||||||
}
|
}
|
||||||
|
|
||||||
function openHelp(){
|
function openHelp() {
|
||||||
browser.tabs.create({
|
browser.tabs.create({
|
||||||
url: browser.extension.getURL('help.html')
|
url: browser.extension.getURL('help.html')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
browser.contextMenus.onClicked.addListener(function (info, tab) {
|
browser.contextMenus.onClicked.addListener(function (info, tab) {
|
||||||
if(info.menuItemId == 'help'){
|
if (info.menuItemId == 'help') {
|
||||||
openHelp();
|
openHelp();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var label = info.menuItemId.substring('mark-'.length);
|
var label = info.menuItemId.substring('mark-'.length);
|
||||||
if(label == 'none') label = '';
|
if (label == 'none') label = '';
|
||||||
browser.tabs.sendMessage(tab.id, {
|
browser.tabs.sendMessage(tab.id, {
|
||||||
mark: label,
|
mark: label,
|
||||||
url: info.linkUrl,
|
url: info.linkUrl,
|
||||||
|
@ -9,7 +9,7 @@ if (hostname.endsWith('.reddit.com')) hostname = 'reddit.com';
|
|||||||
|
|
||||||
var myself = null;
|
var myself = null;
|
||||||
|
|
||||||
function fixupSiteStyles(){
|
function fixupSiteStyles() {
|
||||||
if (hostname == 'reddit.com') {
|
if (hostname == 'reddit.com') {
|
||||||
myself = document.querySelector('#header-bottom-right .user a');
|
myself = document.querySelector('#header-bottom-right .user a');
|
||||||
if (!myself) {
|
if (!myself) {
|
||||||
@ -24,9 +24,9 @@ function fixupSiteStyles(){
|
|||||||
var m = document.querySelector("[id^='profile_pic_header_']")
|
var m = document.querySelector("[id^='profile_pic_header_']")
|
||||||
if (m) myself = 'facebook.com/' + captureRegex(m.id, /header_(\d+)/);
|
if (m) myself = 'facebook.com/' + captureRegex(m.id, /header_(\d+)/);
|
||||||
}
|
}
|
||||||
if(hostname == 'medium.com') {
|
if (hostname == 'medium.com') {
|
||||||
|
|
||||||
|
|
||||||
var style = document.createElement('style');
|
var style = document.createElement('style');
|
||||||
style.textContent = `
|
style.textContent = `
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ function fixupSiteStyles(){
|
|||||||
document.head.appendChild(style);
|
document.head.appendChild(style);
|
||||||
|
|
||||||
}
|
}
|
||||||
if(isHostedOn(hostname, 'tumblr.com')) {
|
if (isHostedOn(hostname, 'tumblr.com')) {
|
||||||
var style = document.createElement('style');
|
var style = document.createElement('style');
|
||||||
style.textContent = `
|
style.textContent = `
|
||||||
.assigned-label-transphobic { outline: 2px solid #991515 !important; }
|
.assigned-label-transphobic { outline: 2px solid #991515 !important; }
|
||||||
@ -71,7 +71,7 @@ function fixupSiteStyles(){
|
|||||||
`;
|
`;
|
||||||
document.head.appendChild(style);
|
document.head.appendChild(style);
|
||||||
|
|
||||||
}else if(hostname == 'reddit.com'){
|
} else if (hostname == 'reddit.com') {
|
||||||
var style = document.createElement('style');
|
var style = document.createElement('style');
|
||||||
style.textContent = `
|
style.textContent = `
|
||||||
.author { color: #369 !important;}
|
.author { color: #369 !important;}
|
||||||
@ -80,19 +80,19 @@ function fixupSiteStyles(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function maybeDisableCustomCss(){
|
function maybeDisableCustomCss() {
|
||||||
var shouldDisable = null;
|
var shouldDisable = 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_');
|
||||||
|
|
||||||
if(shouldDisable)
|
if (shouldDisable)
|
||||||
[...document.styleSheets].filter(shouldDisable).forEach(x => x.disabled = true);
|
[...document.styleSheets].filter(shouldDisable).forEach(x => x.disabled = true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
fixupSiteStyles();
|
fixupSiteStyles();
|
||||||
|
|
||||||
if (isHostedOn(hostname, 'youtube.com')) {
|
if (isHostedOn(hostname, 'youtube.com')) {
|
||||||
setInterval(updateYouTubeChannelHeader, 300);
|
setInterval(updateYouTubeChannelHeader, 300);
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ function init() {
|
|||||||
|
|
||||||
maybeDisableCustomCss();
|
maybeDisableCustomCss();
|
||||||
updateAllLabels();
|
updateAllLabels();
|
||||||
|
|
||||||
var observer = new MutationObserver(mutationsList => {
|
var observer = new MutationObserver(mutationsList => {
|
||||||
maybeDisableCustomCss();
|
maybeDisableCustomCss();
|
||||||
for (var mutation of mutationsList) {
|
for (var mutation of mutationsList) {
|
||||||
@ -141,19 +141,19 @@ var lastRightClickedElement = null;
|
|||||||
var lastAppliedYouTubeUrl = null;
|
var lastAppliedYouTubeUrl = null;
|
||||||
var lastAppliedYouTubeTitle = null;
|
var lastAppliedYouTubeTitle = null;
|
||||||
|
|
||||||
function updateYouTubeChannelHeader(){
|
function updateYouTubeChannelHeader() {
|
||||||
var url = window.location.href;
|
var url = window.location.href;
|
||||||
var title = document.getElementById('channel-title');
|
var title = document.getElementById('channel-title');
|
||||||
if(title && title.tagName == 'H3') title = null; // search results, already a link
|
if (title && title.tagName == 'H3') title = null; // search results, already a link
|
||||||
var currentTitle = title ? title.textContent : null;
|
var currentTitle = title ? title.textContent : null;
|
||||||
|
|
||||||
if(url == lastAppliedYouTubeUrl && currentTitle == lastAppliedYouTubeTitle) return;
|
if (url == lastAppliedYouTubeUrl && currentTitle == lastAppliedYouTubeTitle) return;
|
||||||
lastAppliedYouTubeUrl = url;
|
lastAppliedYouTubeUrl = url;
|
||||||
lastAppliedYouTubeTitle = currentTitle;
|
lastAppliedYouTubeTitle = currentTitle;
|
||||||
|
|
||||||
if(currentTitle) {
|
if (currentTitle) {
|
||||||
var replacement = document.getElementById('channel-title-replacement');
|
var replacement = document.getElementById('channel-title-replacement');
|
||||||
if(!replacement) {
|
if (!replacement) {
|
||||||
replacement = document.createElement('A');
|
replacement = document.createElement('A');
|
||||||
replacement.id = 'channel-title-replacement'
|
replacement.id = 'channel-title-replacement'
|
||||||
replacement.className = title.className;
|
replacement.className = title.className;
|
||||||
@ -215,15 +215,15 @@ function applyLabel(a, identifier) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function initLink(a){
|
function initLink(a) {
|
||||||
var identifier = getIdentifier(a);
|
var identifier = getIdentifier(a);
|
||||||
if (!identifier) return;
|
if (!identifier) return;
|
||||||
|
|
||||||
if(hostname == 'reddit.com'){
|
if (hostname == 'reddit.com') {
|
||||||
if(a.classList.contains('title')) return; // post title (classic)
|
if (a.classList.contains('title')) return; // post title (classic)
|
||||||
var parent = a.parentNode;
|
var parent = a.parentNode;
|
||||||
if(parent && parent.parentNode && parent.parentNode.classList.contains('flat-list')) return; // post buttons (classic)
|
if (parent && parent.parentNode && parent.parentNode.classList.contains('flat-list')) return; // post buttons (classic)
|
||||||
if(a.id && a.id.startsWith('CommentTopMeta')) return; // post date (redesign)
|
if (a.id && a.id.startsWith('CommentTopMeta')) return; // post date (redesign)
|
||||||
}
|
}
|
||||||
|
|
||||||
var label = knownLabels[identifier];
|
var label = knownLabels[identifier];
|
||||||
@ -264,10 +264,10 @@ function takeNthPathComponent(/** @type {string}*/path, /** @type {number}*/nth)
|
|||||||
return path.split('/')[nth + 1] || null;
|
return path.split('/')[nth + 1] || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function captureRegex(str, regex){
|
function captureRegex(str, regex) {
|
||||||
if(!str) return null;
|
if (!str) return null;
|
||||||
var match = str.match(regex);
|
var match = str.match(regex);
|
||||||
if(match && match[1]) return match[1];
|
if (match && match[1]) return match[1];
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,9 +295,9 @@ function getCurrentFacebookPageId() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getIdentifier(urlstr) {
|
function getIdentifier(urlstr) {
|
||||||
try{
|
try {
|
||||||
return getIdentifierInternal(urlstr);
|
return getIdentifierInternal(urlstr);
|
||||||
}catch(e){
|
} catch (e) {
|
||||||
console.warn("Unable to get identifier for " + urlstr);
|
console.warn("Unable to get identifier for " + urlstr);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -376,9 +376,9 @@ function getIdentifierInternal(urlstr) {
|
|||||||
if (!match) return null;
|
if (!match) return null;
|
||||||
return getIdentifierInternal('http://' + match);
|
return getIdentifierInternal('http://' + match);
|
||||||
}
|
}
|
||||||
if(url.search && url.search.includes('http')){
|
if (url.search && url.search.includes('http')) {
|
||||||
for(var q of url.searchParams){
|
for (var q of url.searchParams) {
|
||||||
if(q[1].startsWith('http')) return getIdentifierInternal(q[1]);
|
if (q[1].startsWith('http')) return getIdentifierInternal(q[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -409,18 +409,18 @@ function getIdentifierInternal(urlstr) {
|
|||||||
return 'medium.com' + takeFirstPathComponents(url.pathname, 1).toLowerCase();
|
return 'medium.com' + takeFirstPathComponents(url.pathname, 1).toLowerCase();
|
||||||
}
|
}
|
||||||
if (isHostedOn(host, 'tumblr.com')) {
|
if (isHostedOn(host, 'tumblr.com')) {
|
||||||
if(url.pathname.startsWith('/register/follow/')) {
|
if (url.pathname.startsWith('/register/follow/')) {
|
||||||
var name = takeNthPathComponent(url.pathname, 2);
|
var name = takeNthPathComponent(url.pathname, 2);
|
||||||
return name ? name + '.tumblr.com' : null;
|
return name ? name + '.tumblr.com' : null;
|
||||||
}
|
}
|
||||||
if(host != 'www.tumblr.com' && host != 'assets.tumblr.com' && host.indexOf('.media.') == -1) {
|
if (host != 'www.tumblr.com' && host != 'assets.tumblr.com' && host.indexOf('.media.') == -1) {
|
||||||
if (!url.pathname.startsWith('/tagged/')) return url.host.toLowerCase();
|
if (!url.pathname.startsWith('/tagged/')) return url.host.toLowerCase();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (host.indexOf('.blogspot.') != -1) {
|
if (host.indexOf('.blogspot.') != -1) {
|
||||||
var m = captureRegex(host, /([a-zA-Z0-9\-]*)\.blogspot/);
|
var m = captureRegex(host, /([a-zA-Z0-9\-]*)\.blogspot/);
|
||||||
if(m) return m.toLowerCase() + '.blogspot.com';
|
if (m) return m.toLowerCase() + '.blogspot.com';
|
||||||
}
|
}
|
||||||
|
|
||||||
var id = host;
|
var id = host;
|
||||||
@ -459,7 +459,7 @@ browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
|||||||
if (hostname == 'medium.com' && (classList.contains('streamItem') || classList.contains('streamItemConversationItem'))) return node;
|
if (hostname == 'medium.com' && (classList.contains('streamItem') || classList.contains('streamItemConversationItem'))) return node;
|
||||||
if (hostname == 'youtube.com' && node.tagName == 'YTD-COMMENT-RENDERER') return node;
|
if (hostname == 'youtube.com' && node.tagName == 'YTD-COMMENT-RENDERER') return node;
|
||||||
if (hostname.endsWith('tumblr.com') && (node.dataset.postId || classList.contains('post'))) return node;
|
if (hostname.endsWith('tumblr.com') && (node.dataset.postId || classList.contains('post'))) return node;
|
||||||
|
|
||||||
node = node.parentElement;
|
node = node.parentElement;
|
||||||
}
|
}
|
||||||
//console.log('Reached the top without a satisfying element')
|
//console.log('Reached the top without a satisfying element')
|
||||||
@ -469,13 +469,12 @@ browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
|||||||
var exact = snippets.filter(x => x && x.contains(lastRightClickedElement))[0] || null;
|
var exact = snippets.filter(x => x && x.contains(lastRightClickedElement))[0] || null;
|
||||||
|
|
||||||
message.snippet = exact;
|
message.snippet = exact;
|
||||||
if(message.debug){
|
var debugClass = 'shinigami-eyes-debug-snippet-highlight';
|
||||||
var debugClass = 'shinigami-eyes-debug-snippet-highlight';
|
|
||||||
if(exact){
|
if (exact && message.debug) {
|
||||||
exact.classList.add(debugClass);
|
exact.classList.add(debugClass);
|
||||||
if (message.debug <= 1)
|
if (message.debug <= 1)
|
||||||
setTimeout(() => exact.classList.remove(debugClass), 2500)
|
setTimeout(() => exact.classList.remove(debugClass), 2500)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
sendResponse(message);
|
sendResponse(message);
|
||||||
})
|
})
|
Loading…
x
Reference in New Issue
Block a user