Skip to content

Commit

Permalink
Add dynamic loader
Browse files Browse the repository at this point in the history
Don't globally load site specific content scripts

Resolves #26
  • Loading branch information
kkuehlz committed Sep 16, 2019
1 parent 021ee3b commit acdbfe8
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 21 deletions.
22 changes: 20 additions & 2 deletions platform/chromium/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,31 @@
"dist/js/content/loader.js",
"dist/js/content/walkdom.js",
"dist/js/content/website.js",
"dist/js/content/websites/discord.js",
"dist/js/content/websites/slack.js",
"dist/js/utils/message.js",
"dist/js/utils/webutils.js",
"dist/js/vendor.js"
],
"run_at": "document_end"
},
{
"matches": [
"http://*.discordapp.com/*",
"https://*.discordapp.com/*"
],
"js": [
"dist/js/content/websites/discord.js"
],
"run_at": "document_end"
},
{
"matches": [
"http://*.slack.com/*",
"https://*.slack.com/*"
],
"js": [
"dist/js/content/websites/slack.js"
],
"run_at": "document_end"
}
],
"browser_action": {
Expand Down
22 changes: 20 additions & 2 deletions platform/firefox/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,31 @@
"dist/js/content/loader.js",
"dist/js/content/walkdom.js",
"dist/js/content/website.js",
"dist/js/content/websites/discord.js",
"dist/js/content/websites/slack.js",
"dist/js/utils/message.js",
"dist/js/utils/webutils.js",
"dist/js/vendor.js"
],
"run_at": "document_end"
},
{
"matches": [
"http://*.discordapp.com/*",
"https://*.discordapp.com/*"
],
"js": [
"dist/js/content/websites/discord.js"
],
"run_at": "document_end"
},
{
"matches": [
"http://*.slack.com/*",
"https://*.slack.com/*"
],
"js": [
"dist/js/content/websites/slack.js"
],
"run_at": "document_end"
}
],
"browser_action": {
Expand Down
16 changes: 8 additions & 8 deletions src/content/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@
'use strict';

import { Website } from './website';
import { Slack } from './websites/slack';
import { Discord } from './websites/discord';

export const load = ( location: Location ): Website | null => {
let siteClasses: Website[] = [];

siteClasses.push( new Slack() );
siteClasses.push( new Discord() );
let siteClasses: string[][] = [
[ 'discordapp.com', 'discord' ],
[ 'app.slack.com', 'slack' ]
];

for ( const siteClass of siteClasses ) {
if ( window.location.hostname === siteClass.getDomain() ) {
return siteClass;
const site: string = siteClass[0];
const cls: string = siteClass[1];
if ( window.location.hostname === site ) {
return new ( require( './websites/' + cls ).__Website__ as typeof Website )();
}
}
return null;
Expand Down
8 changes: 2 additions & 6 deletions src/content/website.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
'use strict';

export class Website {
protected domain: string;
constructor () {
if ( new.target === Website ) {
throw new TypeError( 'Cannot construct Website (Abstract)' );
}
this.domain = 'babble.moe';
}

// Called on page initialization. This sets up monitoring for the target encryption elements.
Expand All @@ -50,8 +48,6 @@ export class Website {
clearInput (): boolean {
return true;
}

getDomain (): string {
return this.domain;
}
}

export { Website as __Website__ };
3 changes: 2 additions & 1 deletion src/content/websites/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export class Discord extends Website {
private targetElement: HTMLTextAreaElement | null;
constructor() {
super();
this.domain = 'discordapp.com';
this.targetElement = null;
}

Expand Down Expand Up @@ -66,3 +65,5 @@ export class Discord extends Website {
return true;
}
}

export { Discord as __Website__ }
5 changes: 3 additions & 2 deletions src/content/websites/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
import { Website } from '../website';
import { documentObserver, sendEnterEvent } from '../../utils/webutils';

export class Slack extends Website {
class Slack extends Website {
private targetElement: HTMLElement | null;
constructor() {
super();
this.domain = 'app.slack.com';
this.targetElement = null;
}

Expand Down Expand Up @@ -61,3 +60,5 @@ export class Slack extends Website {
return true;
}
}

export { Slack as __Website__ };

0 comments on commit acdbfe8

Please sign in to comment.