Skip to content

Commit

Permalink
Merge pull request lingua-libre#101 from kabir-afk/feat/replace-block…
Browse files Browse the repository at this point in the history
…ing-web-request-listeners

Feat/replace blocking web request listeners
  • Loading branch information
hugolpz authored Jul 16, 2024
2 parents dbbfcc5 + a4f9a3c commit 59ada42
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 27 deletions.
7 changes: 2 additions & 5 deletions SignItVideosGallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ SignItVideosGallery.prototype.refresh = async function ( files ) {
console.log(await banana.i18n("si-panel-videos-gallery-attribution",url, speaker, i+1, total));
this.$videos.push( $( `
<div style="display: none;">
<video controls="" muted="" preload="auto" src="${ files[ i ].filename }" width="250" class=""></video>
<iframe controls="" muted="" preload="auto" src="${ files[ i ].filename }" class="" allow="autoplay *"></iframe>
${await banana.i18n("si-panel-videos-gallery-attribution",url, speaker, i+1, total)}
</div>
` ) );
Expand All @@ -57,7 +57,7 @@ SignItVideosGallery.prototype.switchVideo = function ( newIndex ) {
this.$videos[ this.currentIndex ].hide();
this.currentIndex = newIndex;
this.$videos[ this.currentIndex ].show();
$currentVideo = this.$videos[ this.currentIndex ].children( 'video' )[ 0 ];
$currentVideo = this.$videos[ this.currentIndex ].children( 'iframe' )[ 0 ];

$( async function () {
param = await browser.storage.local.get( 'twospeed' );
Expand All @@ -84,9 +84,6 @@ SignItVideosGallery.prototype.switchVideo = function ( newIndex ) {
}
})

// After switching, play
$currentVideo.play();

// Arrows disables when on edges
this.currentIndex === 0 ?
this.previousVideoButton.setDisabled( true )
Expand Down
18 changes: 0 additions & 18 deletions background-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,24 +332,6 @@ async function checkActiveTabInjections( tab ) {
}
}

// Edit the header of all pages on-the-fly to bypass Content-Security-Policy
browser.webRequest.onHeadersReceived.addListener(info => {
const headers = info.responseHeaders; // original headers
for (let i=headers.length-1; i>=0; --i) {
let header = headers[i].name.toLowerCase();
if (header === "content-security-policy") { // csp header is found
// modifying media-src; this implies that the directive is already present
headers[i].value = headers[i].value.replace("media-src", "media-src https://commons.wikimedia.org https://upload.wikimedia.org");
}
}
// return modified headers
return {responseHeaders: headers};
}, {
urls: [ "<all_urls>" ], // match all pages
types: [ "main_frame" ] // to focus only the main document of a tab
}, ["blocking", "responseHeaders"]);


/* *************************************************************** */
/* Browser interactions ****************************************** */
var callModal = async function(msg){
Expand Down
2 changes: 1 addition & 1 deletion content_scripts/signit.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
align-items: center;
}

.signit-video video {
.signit-video iframe {
box-shadow: 0 0 0.5rem #999;
width: 100%;
}
Expand Down
2 changes: 1 addition & 1 deletion content_scripts/wpintegration.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
max-width: 300px;
}

.signit-inline-container video {
.signit-inline-container iframe {
box-shadow: 0 0 .5rem #999;
}

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"contextMenus",
"storage",
"webRequest",
"webRequestBlocking",
"alarms"
],
"host_permissions":["https://*/*"],
"content_scripts": [
{
"matches": [
Expand Down
2 changes: 1 addition & 1 deletion popup/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ html, body {
align-items: center;
}

.signit-video video {
.signit-video iframe {
box-shadow: 0 0 .5rem #999;
width: 345px;
}
Expand Down
22 changes: 22 additions & 0 deletions rules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"id": 1,
"priority": 1,
"action": {
"type": "modifyHeaders",
"responseHeaders": [
{
"header": "Content-Security-Policy",
"operation": "set",
"value": "media-src https://commons.wikimedia.org https://upload.wikimedia.org"
}
]
},
"condition": {
"urlFilter": "|https*",
"resourceTypes": [
"main_frame"
]
}
}
]

0 comments on commit 59ada42

Please sign in to comment.