mirror of
https://github.com/AllanWang/Frost-for-Facebook.git
synced 2024-11-10 04:52:38 +01:00
Strip images and update context handler
This commit is contained in:
parent
330bf28573
commit
87469aba96
@ -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="" />
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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");
|
||||
|
@ -1,61 +1,75 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Context menu for links
|
||||
* Largely mimics click_a.js
|
||||
*/
|
||||
(function () {
|
||||
var longClick = false;
|
||||
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 _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;
|
||||
// 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);
|
||||
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;
|
||||
var target = e.target || e.currentTarget || e.srcElement;
|
||||
if (!(target instanceof Element)) {
|
||||
console.log("No element found");
|
||||
return;
|
||||
}
|
||||
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;
|
||||
}
|
||||
// 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);
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
console.log("Context content " + url + " " + text);
|
||||
Frost.contextMenu(url, text);
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
}
|
||||
};
|
||||
document.addEventListener('contextmenu', _frostAContext, true);
|
||||
|
@ -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);
|
||||
for (const h of handlers) {
|
||||
if (h(e, target)) {
|
||||
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);
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
return
|
||||
}
|
||||
console.log(`Context content ${url} ${text}`);
|
||||
Frost.contextMenu(url, text);
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
"use strict";
|
||||
// Emit key once half the viewport is covered
|
||||
(function () {
|
||||
var isReady = function () {
|
||||
return document.body.scrollHeight > innerHeight + 100;
|
||||
|
@ -1,5 +1,4 @@
|
||||
"use strict";
|
||||
// Fetches the header contents if it exists
|
||||
(function () {
|
||||
var header = document.getElementById('mJewelNav');
|
||||
if (header) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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 () {
|
||||
|
@ -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;
|
||||
|
@ -16,7 +16,8 @@
|
||||
"strictNullChecks": true,
|
||||
"noImplicitAny": true,
|
||||
"allowUnreachableCode": true,
|
||||
"allowUnusedLabels": true
|
||||
"allowUnusedLabels": true,
|
||||
"removeComments": true
|
||||
},
|
||||
"include": [
|
||||
"assets/js", "assets/typings"
|
||||
|
Loading…
Reference in New Issue
Block a user