Skip to content

Commit

Permalink
Merge pull request #116 from richardfrost/muting_options
Browse files Browse the repository at this point in the history
Muting options
  • Loading branch information
richardfrost authored Feb 7, 2019
2 parents afb5450 + e7c352b commit e601684
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "advancedprofanityfilter",
"version": "1.3.1",
"version": "2.0.0",
"description": "A browser extension to filter profanity from webpages.",
"main": "filter.js",
"repository": {
Expand Down
4 changes: 3 additions & 1 deletion src/script/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default class Config {
filterWordList: boolean;
globalMatchMethod: number;
muteAudio: boolean;
muteMethod: number;
password: string;
preserveCase: boolean;
preserveFirst: boolean;
Expand Down Expand Up @@ -54,7 +55,8 @@ export default class Config {
filterMethod: 0, // ['Censor', 'Substitute', 'Remove'];
filterWordList: true,
globalMatchMethod: 3, // ['Exact', 'Partial', 'Whole', 'Per-Word', 'RegExp']
muteAudio: false,
muteAudio: false, // Filter audio
muteMethod: 0, // 0: Mute Tab, 1: Video Volume
password: null,
preserveCase: true,
preserveFirst: true,
Expand Down
5 changes: 5 additions & 0 deletions src/script/optionPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,12 @@ export default class OptionPage {

populateAudio() {
let muteAudioInput = document.getElementById('muteAudio') as HTMLInputElement;
let selectedMuteMethod = document.querySelector(`input[name=audioMuteMethod][value='${this.cfg.muteMethod}']`) as HTMLInputElement;
let selectedshowSubtitle = document.querySelector(`input[name=audioShowSubtitles][value='${this.cfg.showSubtitles}']`) as HTMLInputElement;
let muteAudioOptionsContainer = document.getElementById('muteAudioOptionsContainer') as HTMLElement;
muteAudioInput.checked = this.cfg.muteAudio;
this.cfg.muteAudio ? OptionPage.show(muteAudioOptionsContainer) : OptionPage.hide(muteAudioOptionsContainer);
selectedMuteMethod.checked = true;
selectedshowSubtitle.checked = true;
}

Expand Down Expand Up @@ -448,6 +450,7 @@ export default class OptionPage {
let defaultWordSubstitution = document.getElementById('defaultWordSubstitutionText') as HTMLInputElement;
let muteAudioInput = document.getElementById('muteAudio') as HTMLInputElement;
let showSubtitlesInput = document.querySelector('input[name="audioShowSubtitles"]:checked') as HTMLInputElement;
let muteMethodInput = document.querySelector('input[name="audioMuteMethod"]:checked') as HTMLInputElement;
self.cfg.censorCharacter = censorCharacterSelect.value;
self.cfg.censorFixedLength = censorFixedLengthSelect.selectedIndex;
self.cfg.defaultWordMatchMethod = defaultWordMatchMethodSelect.selectedIndex;
Expand All @@ -462,6 +465,7 @@ export default class OptionPage {
self.cfg.substitutionMark = substitutionMark.checked;
self.cfg.defaultSubstitution = defaultWordSubstitution.value.trim().toLowerCase();
self.cfg.muteAudio = muteAudioInput.checked;
self.cfg.muteMethod = parseInt(muteMethodInput.value);
self.cfg.showSubtitles = parseInt(showSubtitlesInput.value);

// Save settings
Expand Down Expand Up @@ -675,6 +679,7 @@ document.getElementById('disabledDomainSave').addEventListener('click', e => { o
document.getElementById('disabledDomainRemove').addEventListener('click', e => { option.disabledDomainRemove(e); });
// Audio
document.getElementById('muteAudio').addEventListener('click', e => { option.saveOptions(e); });
document.querySelectorAll('#audioMuteMethod input').forEach(el => { el.addEventListener('click', e => { option.saveOptions(e); }); });
document.querySelectorAll('#audioSubtitleSelection input').forEach(el => { el.addEventListener('click', e => { option.saveOptions(e); }); });
// Config
document.getElementById('configReset').addEventListener('click', e => { option.confirm(e, 'restoreDefaults'); });
Expand Down
37 changes: 33 additions & 4 deletions src/script/webAudio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,29 @@ export default class WebAudio {
}

static mute(filter) {
if (filter.muted === false) {
if (!filter.muted) {
filter.muted = true;
chrome.runtime.sendMessage({mute: true});

switch(filter.cfg.muteMethod) {
case 0: // Mute tab
chrome.runtime.sendMessage({ mute: true });
break;
case 1: { // Mute video
let video = document.getElementsByTagName('video')[0];
if (video && video.hasOwnProperty('volume')) {
filter.volume = video.volume; // Save original volume
video.volume = 0;
}
break;
}
}
}
}

static playing(video: HTMLMediaElement): boolean {
return !!(video.currentTime > 0 && !video.paused && !video.ended && video.readyState > 2);
}

static subtitleSelector(hostname: string): string {
return WebAudio.subtitleSelectors[hostname];
}
Expand All @@ -63,9 +80,21 @@ export default class WebAudio {
}

static unmute(filter) {
if (filter.muted === true) {
if (filter.muted) {
filter.muted = false;
chrome.runtime.sendMessage({mute: false});

switch(filter.cfg.muteMethod) {
case 0: // Mute tab
chrome.runtime.sendMessage({ mute: false });
break;
case 1: { // Mute video
let video = document.getElementsByTagName('video')[0];
if (video && video.hasOwnProperty('volume')) {
video.volume = filter.volume;
}
break;
}
}
}
}
}
2 changes: 2 additions & 0 deletions src/script/webFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ export default class WebFilter extends Filter {
muted: boolean;
subtitleSelector: string;
summary: object;
volume: number;

constructor() {
super();
this.advanced = false;
this.muted = false;
this.summary = {};
this.volume = 1;
}

// Always use the top frame for page check
Expand Down
2 changes: 1 addition & 1 deletion src/static/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"short_name": "Profanity Filter",
"author": "Richard Frost",
"manifest_version": 2,
"version": "1.3.1",
"version": "2.0.0",
"description": "Advanced Profanity Filter helps to clean up bad language on the websites you and your family visit.",
"icons": {
"16": "img/icon16.png",
Expand Down
44 changes: 39 additions & 5 deletions src/static/optionPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,44 @@ <h4 class="sectionHeader">Instructions</h4>
<li>Turn on subtitles for the video</li>
</ol>

<h4 class="sectionHeader">Mute Method</h4>
<div id="audioMuteMethod">
<label>
<input id="audioMuteMethodTab" type="radio" class="w3-radio" name="audioMuteMethod" value="0">
Browser Tab
</label>

<br>
<label>
<input id="audioMuteMethodVideo" type="radio" class="w3-radio" name="audioMuteMethod" value="1">
Video Volume
</label>
</div>

<h4 class="sectionHeader">Subtitles</h4>
<div id="audioSubtitleSelection">
<label><input id="audioShowAllSubtitles" type="radio" class="w3-radio" name="audioShowSubtitles" value="0">Show all</label>
<label>
<input id="audioShowAllSubtitles" type="radio" class="w3-radio" name="audioShowSubtitles" value="0">
Show all
</label>

<br>
<label><input id="audioShowOnlySubtitles" type="radio" class="w3-radio" name="audioShowSubtitles" value="1">Show only filtered</label>
<label>
<input id="audioShowOnlySubtitles" type="radio" class="w3-radio" name="audioShowSubtitles" value="1">
Show only filtered
</label>

<br>
<label><input id="audioShowOnlySubtitles" type="radio" class="w3-radio" name="audioShowSubtitles" value="2">Show only unfiltered</label>
<label>
<input id="audioShowOnlySubtitles" type="radio" class="w3-radio" name="audioShowSubtitles" value="2">
Show only unfiltered
</label>

<br>
<label><input id="audioHideSubtitles" type="radio" class="w3-radio" name="audioShowSubtitles" value="3">Hide all</label>
<label>
<input id="audioHideSubtitles" type="radio" class="w3-radio" name="audioShowSubtitles" value="3">
Hide all
</label>
</div>
</div>
</div>
Expand Down Expand Up @@ -360,7 +389,12 @@ <h3 id="whitelist-disabled-">Whitelist (Disabled):</h3>
<h1 id="audio-experimental-">Audio (Experimental)</h1>
<p>This feature mutes the audio when a filtered word is detected in the subtitles/captions on a supported website. This is very experimental at this point, and its effectiveness is completely dependent on the quality of the subtitles accompanying the video. For more information, please see the <a href="https://github.com/richardfrost/AdvancedProfanityFilter/wiki/Audio">Audio wiki</a>.</p>
<ul>
<li><strong>Mute tab audio on supported video sites</strong> - Enables the feature. Without this on audio filtering will occur.</li>
<li><strong>Mute audio on supported video sites</strong> - Enables the feature. Without this no audio filtering will occur.</li>
<li><strong>Mute Method</strong> - Controls which method to use for muting audio<ul>
<li>Browser Tab - Disables all audio from the current browser tab</li>
<li>Video Volume - Changes the video volume to 0 when necessary</li>
</ul>
</li>
<li><strong>Subtitles</strong> - Controls which subtitles will be visible.<ul>
<li>Show all subtitles (<em>default</em>)</li>
<li>Show only filtered subtitles - Least distracting</li>
Expand Down

0 comments on commit e601684

Please sign in to comment.