Skip to content

Commit

Permalink
Removed styling method and fixed new Regex, #7
Browse files Browse the repository at this point in the history
  • Loading branch information
basshelal committed Sep 14, 2019
1 parent a1af5ae commit 8b902fd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 60 deletions.
44 changes: 16 additions & 28 deletions chrome/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var arabicRegEx = new RegExp("([\u0600-\u06FF\u0750-\u077F\u08a0-\u08ff\uFB50-\u
* This Arabic regex allows and accepts any non Arabic symbols next to Arabic symbols,
* this means that it accepts anything as long as it has some Arabic symbol in it
*/
var newArabicRegex = new RegExp(".+[\u0600-\u06FF\u0750-\u077F\u08a0-\u08ff\uFB50-\uFDFF\uFE70-\uFEFF\u0600-\u06FF\u0750-\u077F\u08a0-\u08ff\uFB50-\uFDFF\uFE70-\uFEFF]+", "g");
var newArabicRegex = new RegExp(".+[\u0600-\u06FF\u0750-\u077F\u08a0-\u08ff\uFB50-\uFDFF\uFE70-\uFEFF\u0600-\u06FF\u0750-\u077F\u08a0-\u08ff\uFB50-\uFDFF\uFE70-\uFEFF]+.+", "g");
var defaultFont = "Droid Arabic Naskh";
// TODO figure out a way to have common code in one place instead of all this duplicated code
/** The keys of the {@linkcode chrome.storage.sync} */
Expand Down Expand Up @@ -142,34 +142,24 @@ function updateNode(node, textSize, lineHeight, font) {
if (node.nodeValue) {
var newSize = textSize / 100;
var newHeight = lineHeight / 100;
var newHTML = void 0;
var element = node.parentElement;
if (font === "Original") {
newHTML = "<span wudooh='true'' style='" +
"font-size:" + newSize + "em;" +
"line-height:" + newHeight + "em;" +
"'>$&</span>";
var text = node.nodeValue.replace(newArabicRegex, newHTML);
setNodeHtml(node, text);
} else {
updateByAdding(node, newSize, newHeight, font);
}
updateByAdding(node, newSize, newHeight, font);
}
}
// TODO remove this later
function updateByStyling(element, textSize, lineHeight, font) {
element.dir = "rtl";
element.style.fontSize = textSize + "em";
element.style.lineHeight = lineHeight + "em";
element.style.fontFamily = "\"" + font + "\"" + "," + "sans-serif";
element.setAttribute("wudooh", "true");
}

function updateByAdding(node, textSize, lineHeight, font) {
var newHTML = "<span wudooh='true' style='" +
"font-size:" + textSize + "em;" +
"line-height:" + lineHeight + "em;" +
"font-family:" + "\"" + font + "\"" + "," + "sans-serif;" +
"'>$&</span>";
var newHTML;
if (font === "Original") {
newHTML = "<span wudooh='true'' style='" +
"font-size:" + textSize + "em;" +
"line-height:" + lineHeight + "em;" +
"'>$&</span>";
} else {
newHTML = "<span wudooh='true' style='" +
"font-size:" + textSize + "em;" +
"line-height:" + lineHeight + "em;" +
"font-family:" + "\"" + font + "\"" + "," + "sans-serif;" +
"'>$&</span>";
}
var text = node.nodeValue.replace(newArabicRegex, newHTML);
setNodeHtml(node, text);
}
Expand Down Expand Up @@ -276,7 +266,6 @@ sync.get(keys, function (fromStorage) {
startObserver(textSize, lineHeight, font);
notify();
}
log();
});
/**
* Listener to update text if options are modified, the options being text size, line height and font
Expand All @@ -294,7 +283,6 @@ runtime.onMessage.addListener(function (message) {
observer = null;
}
startObserver(newSize, newHeight, message.font);
log();
});
// TODO REMOVE LATER!
function log() {
Expand Down
48 changes: 16 additions & 32 deletions chrome/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const arabicRegEx = new RegExp("([\u0600-\u06FF\u0750-\u077F\u08a0-\u08ff\uFB50-
* This Arabic regex allows and accepts any non Arabic symbols next to Arabic symbols,
* this means that it accepts anything as long as it has some Arabic symbol in it
*/
const newArabicRegex = new RegExp(".+[\u0600-\u06FF\u0750-\u077F\u08a0-\u08ff\uFB50-\uFDFF\uFE70-\uFEFF\u0600-\u06FF\u0750-\u077F\u08a0-\u08ff\uFB50-\uFDFF\uFE70-\uFEFF]+", "g");
const newArabicRegex = new RegExp(".+[\u0600-\u06FF\u0750-\u077F\u08a0-\u08ff\uFB50-\uFDFF\uFE70-\uFEFF\u0600-\u06FF\u0750-\u077F\u08a0-\u08ff\uFB50-\uFDFF\uFE70-\uFEFF]+.+", "g");

const defaultFont: string = "Droid Arabic Naskh";

Expand Down Expand Up @@ -175,37 +175,25 @@ function updateNode(node: Node, textSize: number, lineHeight: number, font: stri
if (node.nodeValue) {
let newSize: number = textSize / 100;
let newHeight: number = lineHeight / 100;
let newHTML: string;
let element: HTMLElement = node.parentElement;

if (font === "Original") {
newHTML = "<span wudooh='true'' style='" +
"font-size:" + newSize + "em;" +
"line-height:" + newHeight + "em;" +
"'>$&</span>";
let text: string = node.nodeValue.replace(newArabicRegex, newHTML);
setNodeHtml(node, text);
} else {
updateByAdding(node, newSize, newHeight, font);
}
}
}

// TODO remove this later
function updateByStyling(element: HTMLElement, textSize: number, lineHeight: number, font: string) {
element.dir = "rtl";
element.style.fontSize = textSize + "em";
element.style.lineHeight = lineHeight + "em";
element.style.fontFamily = "\"" + font + "\"" + "," + "sans-serif";
element.setAttribute("wudooh", "true");
updateByAdding(node, newSize, newHeight, font);
}
}

function updateByAdding(node: Node, textSize: number, lineHeight: number, font: string) {
let newHTML = "<span wudooh='true' style='" +
"font-size:" + textSize + "em;" +
"line-height:" + lineHeight + "em;" +
"font-family:" + "\"" + font + "\"" + "," + "sans-serif;" +
"'>$&</span>";
let newHTML: string;
if (font === "Original") {
newHTML = "<span wudooh='true'' style='" +
"font-size:" + textSize + "em;" +
"line-height:" + lineHeight + "em;" +
"'>$&</span>";
} else {
newHTML = "<span wudooh='true' style='" +
"font-size:" + textSize + "em;" +
"line-height:" + lineHeight + "em;" +
"font-family:" + "\"" + font + "\"" + "," + "sans-serif;" +
"'>$&</span>";
}

let text: string = node.nodeValue.replace(newArabicRegex, newHTML);
setNodeHtml(node, text);
Expand Down Expand Up @@ -320,8 +308,6 @@ sync.get(keys, (fromStorage) => {
startObserver(textSize, lineHeight, font);
notify();
}

log();
});

/**
Expand All @@ -341,8 +327,6 @@ runtime.onMessage.addListener((message) => {
observer = null;
}
startObserver(newSize, newHeight, message.font);

log()
});

// TODO REMOVE LATER!
Expand Down

0 comments on commit 8b902fd

Please sign in to comment.