Start adding some types

This commit is contained in:
shinigami-eyes 2019-06-29 15:16:27 +02:00
parent 2f524bac7a
commit bea4257a53
5 changed files with 36 additions and 12 deletions

View File

@ -1,9 +1,9 @@
var browser = browser || chrome; var browser : Browser = browser || chrome;
var PENDING_SUBMISSIONS = ':PENDING_SUBMISSIONS' const PENDING_SUBMISSIONS = ':PENDING_SUBMISSIONS'
var MIGRATION = ':MIGRATION' const MIGRATION = ':MIGRATION'
var CURRENT_VERSION = 100018; const CURRENT_VERSION = 100018;
// If a user labels one of these URLs, they're making a mistake. Ignore the label. // If a user labels one of these URLs, they're making a mistake. Ignore the label.
// This list includes: // This list includes:
@ -232,7 +232,7 @@ var badIdentifiersArray = [
'youtube.com/redirect', 'youtube.com/redirect',
'youtube.com/watch', 'youtube.com/watch',
]; ];
var badIdentifiers = {}; var badIdentifiers : {[id: string]: true} = {};
badIdentifiersArray.forEach(x => badIdentifiers[x] = true); badIdentifiersArray.forEach(x => badIdentifiers[x] = true);
var lastSubmissionError = null; var lastSubmissionError = null;
@ -287,9 +287,9 @@ browser.storage.local.get(['overrides', 'accepted', 'installationId'], v => {
} }
}) })
var bloomFilters = []; const bloomFilters : BloomFilter[] = [];
function loadBloomFilter(name) { function loadBloomFilter(name: string) {
var url = browser.extension.getURL('data/' + name + '.dat'); var url = browser.extension.getURL('data/' + name + '.dat');
fetch(url).then(response => { fetch(url).then(response => {
@ -341,7 +341,7 @@ loadBloomFilter('t-friendly');
function createContextMenu(text, id) { function createContextMenu(text: string, id: ContextMenuCommand) {
browser.contextMenus.create({ browser.contextMenus.create({
id: id, id: id,
title: text, title: text,

View File

@ -1,4 +1,4 @@
var 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.')) {
@ -15,7 +15,7 @@ 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) {
var m = document.querySelector('#USER_DROPDOWN_ID'); var m : any = document.querySelector('#USER_DROPDOWN_ID');
if (m) { if (m) {
m = [...m.querySelectorAll('*')].filter(x => x.childNodes.length == 1 && x.firstChild.nodeType == 3).map(x => x.textContent)[0] m = [...m.querySelectorAll('*')].filter(x => x.childNodes.length == 1 && x.firstChild.nodeType == 3).map(x => x.textContent)[0]
if (m) myself = 'reddit.com/user/' + m; if (m) myself = 'reddit.com/user/' + m;
@ -23,7 +23,7 @@ function fixupSiteStyles() {
} }
} }
if (hostname == 'facebook.com') { if (hostname == 'facebook.com') {
var m = document.querySelector("[id^='profile_pic_header_']") var m : any = 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') {

6
extension/definitions.d.ts vendored Normal file
View File

@ -0,0 +1,6 @@
declare class BloomFilter {
constructor(data: Uint32Array, k: number);
test(key: string): boolean;
name: string;
}
type ContextMenuCommand = 'mark-t-friendly' | 'mark-transphobic' | 'mark-none' | 'help';

View File

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

18
extension/webextensions.d.ts vendored Normal file
View File

@ -0,0 +1,18 @@
declare type Browser = {
runtime: {
}
storage: {
local: BrowserStorage
}
extension: {
}
}
declare type BrowserStorage = {
}
declare var browser : Browser;
declare var chrome : Browser;