Skip to content

Commit

Permalink
Merge pull request lingua-libre#83 from kabir-afk/master
Browse files Browse the repository at this point in the history
Multiple Code Enhancements
  • Loading branch information
hugolpz authored Jun 7, 2024
2 parents fb73fae + 63e9ab6 commit baf2b27
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 56 deletions.
6 changes: 3 additions & 3 deletions SignItVideosGallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ var SignItVideosGallery = function ( container ) {
this.videos = [];
this.currentIndex = 0;

this.previousVideoButton = new OO.ui.ButtonWidget( { icon: 'previous', framed: false } );
this.nextVideoButton = new OO.ui.ButtonWidget( { icon: 'next', framed: false } );
this.previousVideoButton = new OO.ui.ButtonWidget( { icon: 'previousBtn', framed: false } );
this.nextVideoButton = new OO.ui.ButtonWidget( { icon: 'nextBtn', framed: false } );
this.$videoContainer = $( '<div class="signit-panel-videos-gallery">' );

container.append( this.previousVideoButton.$element ).append( this.$videoContainer ).append( this.nextVideoButton.$element );
Expand All @@ -24,7 +24,7 @@ SignItVideosGallery.prototype.refresh = async function ( files ) {
var banana = {
i18n: (msg, url, speaker,index, total) => {
let string = sourceMap.get(locale)[msg];
let Speaker = `<a href=${url}>${speaker} </a>`;
let Speaker = `<a href=${url} target="_blank">${speaker} </a>`;
let patterns = ["{{link|$1|$2}}", "$3", "$4"];
let replacements = [Speaker, index, total];

Expand Down
16 changes: 11 additions & 5 deletions content_scripts/wpintegration.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@
box-shadow: 0 0 .5rem #999;
}

.oo-ui-icon-next {
background-image: url('../icons/arrow-right-solid.svg' )}
.oo-ui-icon-nextBtn , .oo-ui-icon-previousBtn{
padding-top: 5px;
}
.oo-ui-icon-nextBtn::after {
content: "\25B6";
}

.oo-ui-icon-previous {
background-image: url('../icons/arrow-left-solid.svg' )}
.oo-ui-icon-previousBtn::after {
content: "\25C0";
}

.oo-ui-icon-search {
background-image: url('../icons/magnifying-glass-solid.svg' )}
background-image: url('../icons/magnifying-glass-solid.svg' )
}
2 changes: 1 addition & 1 deletion content_scripts/wpintegration.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ $( async function () {
}

title = $( 'h1.firstHeading' ).text();
files = await browser.runtime.sendMessage({
files = await chrome.runtime.sendMessage({
command: 'signit.getfiles',
wpTitle: title
});
Expand Down
11 changes: 7 additions & 4 deletions popup/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,15 @@ html, body {
margin: auto;
}

.oo-ui-icon-next {
background-image: url( '../icons/arrow-right-solid.svg' );
.oo-ui-icon-nextBtn , .oo-ui-icon-previousBtn{
padding-top: 5px;
}
.oo-ui-icon-nextBtn::after {
content: "\25B6";
}

.oo-ui-icon-previous {
background-image: url( '../icons/arrow-left-solid.svg' );
.oo-ui-icon-previousBtn::after {
content: "\25C0";
}

.oo-ui-icon-search {
Expand Down
10 changes: 8 additions & 2 deletions popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ var browser = (browserType === 'firefox') ? browser : (browserType === 'chrome')
// which fetches the messages from sourceMap and replpace them with whatever the key-value pair
// for that particular message is

banana = {i18n: msg => sourceMap.get(resArr[1])[msg]};
banana = {i18n: (msg,argument) => {
let string = sourceMap.get(resArr[1])[msg];
if ((/\$1/).test(string)) {
string = string.replace(/\$1/,argument);
}
return string;
}};
console.log("banana received: ",banana);
} else if (browserType === 'firefox') {
// Use Firefox WebExtensions API
Expand Down Expand Up @@ -130,7 +136,7 @@ var browser = (browserType === 'firefox') ? browser : (browserType === 'chrome')

UI.prototype.changeView = async function (text) {
if (typeof text !== "string") {
// text = this.searchWidget.getValue();
text = this.searchWidget.getValue();
}
// runs normalize function and wordToFiles in a single go and retruns an array of _word and _files

Expand Down
56 changes: 15 additions & 41 deletions sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,21 +575,20 @@ async function setState(value) {
}

// Check a string with multiple words and return the word whose record is available
function getAvailableWord(word) {
const wordArray = word.split(" ");
// For some reason iterating through array returns undefined so I switched to filter method

// for ( let newWord of wordArray ) {
// if( records.hasOwnProperty(newWord.toLowerCase()) ){
// return newWord;
// }
// }
wordArray.filter((e) => {
if (records.hasOwnProperty(e.toLowerCase())) return e;
});
return wordArray[0];
}
function getAvailableWord( word ) {

// similar to what we did in background-script.js;

const regex = /[!"#$%&()*+,-./:;<=>?@[\\\]^_{|}~]/;
const stringWithoutSpecialChars = word.replace(regex,"");
const wordArray = stringWithoutSpecialChars.split(" ");
console.log(wordArray);
for ( let newWord of wordArray ) {
if( records.hasOwnProperty(newWord.toLowerCase()) ){
return newWord;
}
}
}
// Given a word string, check if exist in available records data, if so return data on that word
// returns format: { filename: url, speaker: name }
function wordToFiles(word) {
Expand Down Expand Up @@ -623,22 +622,17 @@ async function setState(value) {
try {
await browser.tabs.sendMessage(tabId, { command: "ping" });
} catch (error) {
// var i,
var dependencies = browser.runtime.getManifest().content_scripts[0];
var scripts = dependencies.js;
var stylesheets = dependencies.css;

// Using the scripting API as per Manifest V3

// for( i = 0; i < scripts.length; i++ ) {
// await browser.scripting.executeScript( tab, { file: scripts[ i ] } );
await browser.scripting.executeScript({
target: { tabId },
files: [...scripts],
});
// }
// for( i = 0; i < stylesheets.length; i++ ) {
// await browser.tabs.insertCSS( tab, { file: stylesheets[ i ] } );

await browser.scripting.insertCSS({
target: { tabId },
files: [...stylesheets],
Expand All @@ -647,26 +641,6 @@ async function setState(value) {
}
}

// Insecure CSP not supported in manifest V3 , so no need to for the bypass logic

// 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) {
// Tab
Expand Down Expand Up @@ -740,7 +714,7 @@ async function setState(value) {
console.log(
records[message.text] || records[message.text.toLowerCase()] || []
);
return records[message.text] || records[message.text.toLowerCase()] || [];
sendResponse(records[message.text] || records[message.text.toLowerCase()] || []);
}
// When message 'signit.i18nCode' is heard, returns banada object
else if (
Expand Down

0 comments on commit baf2b27

Please sign in to comment.