aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/res/xml/frost_changelog.xml4
-rw-r--r--app/src/web/assets/js/click_a.js9
-rw-r--r--app/src/web/assets/js/click_debugger.js2
-rw-r--r--app/src/web/assets/js/context_a.js100
-rw-r--r--app/src/web/assets/js/context_a.ts108
-rw-r--r--app/src/web/assets/js/document_watcher.js1
-rw-r--r--app/src/web/assets/js/header_badges.js1
-rw-r--r--app/src/web/assets/js/media.js2
-rw-r--r--app/src/web/assets/js/menu.js2
-rw-r--r--app/src/web/assets/js/notif_msg.js1
-rw-r--r--app/src/web/assets/js/textarea_listener.js8
-rw-r--r--app/src/web/tsconfig.json3
12 files changed, 133 insertions, 108 deletions
diff --git a/app/src/main/res/xml/frost_changelog.xml b/app/src/main/res/xml/frost_changelog.xml
index f90ecf37..ed014604 100644
--- a/app/src/main/res/xml/frost_changelog.xml
+++ b/app/src/main/res/xml/frost_changelog.xml
@@ -8,8 +8,8 @@
<version title="v2.2.2" />
<item text="New marketplace shortcut" />
- <item text="" />
- <item text="" />
+ <item text="Fix crash when internet disconnects (may still need app restart)" />
+ <item text="Improve JS code" />
<item text="" />
<item text="" />
diff --git a/app/src/web/assets/js/click_a.js b/app/src/web/assets/js/click_a.js
index 7faafc15..be69bb8c 100644
--- a/app/src/web/assets/js/click_a.js
+++ b/app/src/web/assets/js/click_a.js
@@ -2,14 +2,12 @@
(function () {
var prevented = false;
var _frostAClick = function (e) {
- // check for valid target
var target = e.target || e.currentTarget || e.srcElement;
if (!(target instanceof Element)) {
console.log("No element found");
return;
}
var element = target;
- // Notifications are two layers under
for (var i = 0; i < 2; i++) {
if (element.tagName !== 'A') {
element = element.parentElement;
@@ -22,7 +20,6 @@
return;
}
console.log("Click intercept " + url);
- // If Frost is injected, check if loading the url through an overlay works
if (Frost.loadUrl(url)) {
e.stopPropagation();
e.preventDefault();
@@ -33,12 +30,6 @@
}
}
};
- /*
- * On top of the click event, we must stop it for long presses
- * Since that will conflict with the context menu
- * Note that we only override it on conditions where the context menu
- * Will occur
- */
var _frostPreventClick = function () {
console.log("Click _frostPrevented");
prevented = true;
diff --git a/app/src/web/assets/js/click_debugger.js b/app/src/web/assets/js/click_debugger.js
index aab4572d..16729899 100644
--- a/app/src/web/assets/js/click_debugger.js
+++ b/app/src/web/assets/js/click_debugger.js
@@ -1,8 +1,6 @@
"use strict";
-// For desktop only
(function () {
var _frostAContext = function (e) {
- // Commonality; check for valid target
var element = e.target || e.currentTarget || e.srcElement;
if (!(element instanceof Element)) {
console.log("No element found");
diff --git a/app/src/web/assets/js/context_a.js b/app/src/web/assets/js/context_a.js
index 7e636cea..0573a17a 100644
--- a/app/src/web/assets/js/context_a.js
+++ b/app/src/web/assets/js/context_a.js
@@ -1,61 +1,75 @@
"use strict";
-/**
- * Context menu for links
- * Largely mimics click_a.js
- */
(function () {
var longClick = false;
+ var _frostCopyPost = function (e, target) {
+ if (target.tagName != 'A') {
+ return false;
+ }
+ var parent1 = target.parentElement;
+ if (!parent1 || parent1.tagName != 'DIV') {
+ return false;
+ }
+ var parent2 = parent1.parentElement;
+ if (!parent2 || !parent2.classList.contains('story_body_container')) {
+ return false;
+ }
+ var url = target.getAttribute('href');
+ var text = parent1.innerText;
+ Frost.contextMenu(url, text);
+ return true;
+ };
+ var _frostImage = function (e, target) {
+ var element = target;
+ for (var i = 0; i < 2; i++) {
+ if (element.tagName != 'A') {
+ element = element.parentElement;
+ }
+ }
+ if (element.tagName != 'A') {
+ return false;
+ }
+ var url = element.getAttribute('href');
+ if (!url || url == '#') {
+ return false;
+ }
+ var text = element.parentElement.innerText;
+ var image = element.querySelector("[style*=\"background-image: url(\"]");
+ if (!image) {
+ image = element.parentElement.querySelector("[style*=\"background-image: url(\"]");
+ }
+ if (image) {
+ var imageUrl = window.getComputedStyle(image, null).backgroundImage.trim().slice(4, -1);
+ console.log("Context image: " + imageUrl);
+ Frost.loadImage(imageUrl, text);
+ return true;
+ }
+ var img = element.querySelector("img[src*=scontent]");
+ if (img instanceof HTMLMediaElement) {
+ var imgUrl = img.src;
+ console.log("Context img: " + imgUrl);
+ Frost.loadImage(imgUrl, text);
+ return true;
+ }
+ console.log("Context content " + url + " " + text);
+ Frost.contextMenu(url, text);
+ return true;
+ };
+ var handlers = [_frostCopyPost, _frostImage];
var _frostAContext = function (e) {
Frost.longClick(true);
longClick = true;
- /*
- * Commonality; check for valid target
- */
var target = e.target || e.currentTarget || e.srcElement;
if (!(target instanceof Element)) {
console.log("No element found");
return;
}
- var element = target;
- // Notifications are two layers under
- for (var i = 0; i < 2; i++) {
- if (element.tagName != 'A') {
- element = element.parentElement;
- }
- }
- if (element.tagName == 'A') {
- var url = element.getAttribute('href');
- if (!url || url == '#') {
- return;
- }
- var text = element.parentElement.innerText;
- // Check if image item exists, first in children and then in parent
- var image = element.querySelector("[style*=\"background-image: url(\"]");
- if (!image) {
- image = element.parentElement.querySelector("[style*=\"background-image: url(\"]");
- }
- if (image) {
- var imageUrl = window.getComputedStyle(image, null).backgroundImage.trim().slice(4, -1);
- console.log("Context image: " + imageUrl);
- Frost.loadImage(imageUrl, text);
- e.stopPropagation();
- e.preventDefault();
- return;
- }
- // Check if true img exists
- var img = element.querySelector("img[src*=scontent]");
- if (img instanceof HTMLMediaElement) {
- var imgUrl = img.src;
- console.log("Context img: " + imgUrl);
- Frost.loadImage(imgUrl, text);
+ for (var _i = 0, handlers_1 = handlers; _i < handlers_1.length; _i++) {
+ var h = handlers_1[_i];
+ if (h(e, target)) {
e.stopPropagation();
e.preventDefault();
return;
}
- console.log("Context content " + url + " " + text);
- Frost.contextMenu(url, text);
- e.stopPropagation();
- e.preventDefault();
}
};
document.addEventListener('contextmenu', _frostAContext, true);
diff --git a/app/src/web/assets/js/context_a.ts b/app/src/web/assets/js/context_a.ts
index 16ed33a9..06d2f4a2 100644
--- a/app/src/web/assets/js/context_a.ts
+++ b/app/src/web/assets/js/context_a.ts
@@ -2,8 +2,78 @@
* Context menu for links
* Largely mimics click_a.js
*/
+
(function () {
let longClick = false;
+
+ /**
+ * Given event and target, return true if handled and false otherwise.
+ */
+ type EventHandler = (e: Event, target: Element) => Boolean
+
+ /**
+ * Posts should click a tag, with two parents up being div.story_body_container
+ */
+ const _frostCopyPost: EventHandler = (e, target) => {
+ if (target.tagName != 'A') {
+ return false;
+ }
+ const parent1 = target.parentElement;
+ if (!parent1 || parent1.tagName != 'DIV') {
+ return false;
+ }
+ const parent2 = parent1.parentElement;
+ if (!parent2 || !parent2.classList.contains('story_body_container')) {
+ return false;
+ }
+ const url = target.getAttribute('href')!;
+ const text = parent1.innerText;
+ Frost.contextMenu(url, text);
+ return true;
+ };
+
+ const _frostImage: EventHandler = (e, target) => {
+ let element: Element = target;
+ // Notifications are two layers under
+ for (let i = 0; i < 2; i++) {
+ if (element.tagName != 'A') {
+ element = <Element>element.parentElement;
+ }
+ }
+ if (element.tagName != 'A') {
+ return false
+ }
+ const url = element.getAttribute('href');
+ if (!url || url == '#') {
+ return false
+ }
+ const text = (<HTMLElement>element.parentElement).innerText;
+ // Check if image item exists, first in children and then in parent
+ let image = element.querySelector("[style*=\"background-image: url(\"]");
+ if (!image) {
+ image = (<Element>element.parentElement).querySelector("[style*=\"background-image: url(\"]")
+ }
+ if (image) {
+ const imageUrl = (<String>window.getComputedStyle(image, null).backgroundImage).trim().slice(4, -1);
+ console.log(`Context image: ${imageUrl}`);
+ Frost.loadImage(imageUrl, text);
+ return true
+ }
+ // Check if true img exists
+ const img = element.querySelector("img[src*=scontent]");
+ if (img instanceof HTMLMediaElement) {
+ const imgUrl = img.src;
+ console.log(`Context img: ${imgUrl}`);
+ Frost.loadImage(imgUrl, text);
+ return true
+ }
+ console.log(`Context content ${url} ${text}`);
+ Frost.contextMenu(url, text);
+ return true
+ };
+
+ const handlers = [_frostCopyPost, _frostImage];
+
const _frostAContext = (e: Event) => {
Frost.longClick(true);
longClick = true;
@@ -16,46 +86,12 @@
console.log("No element found");
return
}
- let element: Element = target;
- // Notifications are two layers under
- for (let i = 0; i < 2; i++) {
- if (element.tagName != 'A') {
- element = <Element>element.parentElement;
- }
- }
- if (element.tagName == 'A') {
- const url = element.getAttribute('href');
- if (!url || url == '#') {
- return
- }
- const text = (<HTMLElement>element.parentElement).innerText;
- // Check if image item exists, first in children and then in parent
- let image = element.querySelector("[style*=\"background-image: url(\"]");
- if (!image) {
- image = (<Element>element.parentElement).querySelector("[style*=\"background-image: url(\"]")
- }
- if (image) {
- const imageUrl = (<String>window.getComputedStyle(image, null).backgroundImage).trim().slice(4, -1);
- console.log(`Context image: ${imageUrl}`);
- Frost.loadImage(imageUrl, text);
- e.stopPropagation();
- e.preventDefault();
- return
- }
- // Check if true img exists
- const img = element.querySelector("img[src*=scontent]");
- if (img instanceof HTMLMediaElement) {
- const imgUrl = img.src;
- console.log(`Context img: ${imgUrl}`);
- Frost.loadImage(imgUrl, text);
+ for (const h of handlers) {
+ if (h(e, target)) {
e.stopPropagation();
e.preventDefault();
return
}
- console.log(`Context content ${url} ${text}`);
- Frost.contextMenu(url, text);
- e.stopPropagation();
- e.preventDefault();
}
};
diff --git a/app/src/web/assets/js/document_watcher.js b/app/src/web/assets/js/document_watcher.js
index f3c4ab25..12252201 100644
--- a/app/src/web/assets/js/document_watcher.js
+++ b/app/src/web/assets/js/document_watcher.js
@@ -1,5 +1,4 @@
"use strict";
-// Emit key once half the viewport is covered
(function () {
var isReady = function () {
return document.body.scrollHeight > innerHeight + 100;
diff --git a/app/src/web/assets/js/header_badges.js b/app/src/web/assets/js/header_badges.js
index daaf540a..b1ceee05 100644
--- a/app/src/web/assets/js/header_badges.js
+++ b/app/src/web/assets/js/header_badges.js
@@ -1,5 +1,4 @@
"use strict";
-// Fetches the header contents if it exists
(function () {
var header = document.getElementById('mJewelNav');
if (header) {
diff --git a/app/src/web/assets/js/media.js b/app/src/web/assets/js/media.js
index 571168d6..baeba0a1 100644
--- a/app/src/web/assets/js/media.js
+++ b/app/src/web/assets/js/media.js
@@ -1,5 +1,4 @@
"use strict";
-// Handles media events
(function () {
var _frostMediaClick = function (e) {
var target = e.target || e.srcElement;
@@ -30,7 +29,6 @@
return;
}
var url = dataStore.src;
- // !startsWith; see https://stackoverflow.com/a/36876507/4407321
if (!url || url.lastIndexOf('http', 0) !== 0) {
return;
}
diff --git a/app/src/web/assets/js/menu.js b/app/src/web/assets/js/menu.js
index c30e93cf..b6a30209 100644
--- a/app/src/web/assets/js/menu.js
+++ b/app/src/web/assets/js/menu.js
@@ -1,5 +1,4 @@
"use strict";
-// Click menu and move contents to main view
(function () {
var viewport = document.querySelector("#viewport");
var root = document.querySelector("#root");
@@ -35,7 +34,6 @@
if (menu) {
x.disconnect();
console.log("Found side menu");
- // Transfer elements
while (root.firstChild) {
root.removeChild(root.firstChild);
}
diff --git a/app/src/web/assets/js/notif_msg.js b/app/src/web/assets/js/notif_msg.js
index 20a89e88..bcff697b 100644
--- a/app/src/web/assets/js/notif_msg.js
+++ b/app/src/web/assets/js/notif_msg.js
@@ -1,5 +1,4 @@
"use strict";
-// Binds callback to an invisible webview to take in the search events
(function () {
var finished = false;
var x = new MutationObserver(function () {
diff --git a/app/src/web/assets/js/textarea_listener.js b/app/src/web/assets/js/textarea_listener.js
index 9a8783c1..02336382 100644
--- a/app/src/web/assets/js/textarea_listener.js
+++ b/app/src/web/assets/js/textarea_listener.js
@@ -1,12 +1,4 @@
"use strict";
-/*
- * focus listener for textareas
- * since swipe to refresh is quite sensitive, we will disable it
- * when we detect a user typing
- * note that this extends passed having a keyboard opened,
- * as a user may still be reviewing his/her post
- * swiping should automatically be reset on refresh
- */
(function () {
var _frostFocus = function (e) {
var element = e.target || e.srcElement;
diff --git a/app/src/web/tsconfig.json b/app/src/web/tsconfig.json
index 711fdcbb..ea88e28e 100644
--- a/app/src/web/tsconfig.json
+++ b/app/src/web/tsconfig.json
@@ -16,7 +16,8 @@
"strictNullChecks": true,
"noImplicitAny": true,
"allowUnreachableCode": true,
- "allowUnusedLabels": true
+ "allowUnusedLabels": true,
+ "removeComments": true
},
"include": [
"assets/js", "assets/typings"