kopia lustrzana https://github.com/lartsch/FediAct
attempt to fix element not being detected on v3 (caching issue, el. already on page on load so domnodeappear does not work)
rodzic
8a5f988318
commit
478a2b1101
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "FediAct",
|
"name": "FediAct",
|
||||||
"version": "0.9.5.2",
|
"version": "0.9.5.3",
|
||||||
"description": "Simplifies interactions on other Mastodon instances than your own. Visit https://github.com/lartsch/FediFollow-Chrome for more.",
|
"description": "Simplifies interactions on other Mastodon instances than your own. Visit https://github.com/lartsch/FediFollow-Chrome for more.",
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "FediAct",
|
"name": "FediAct",
|
||||||
"version": "0.9.5.2",
|
"version": "0.9.5.3",
|
||||||
"description": "Simplifies interactions on other Mastodon instances than your own. Visit https://github.com/lartsch/FediFollow-Chrome for more.",
|
"description": "Simplifies interactions on other Mastodon instances than your own. Visit https://github.com/lartsch/FediFollow-Chrome for more.",
|
||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
|
|
126
src/inject.js
126
src/inject.js
|
@ -40,7 +40,7 @@ const settingsDefaults = {
|
||||||
var browser, chrome, lasthomerequest, fedireply
|
var browser, chrome, lasthomerequest, fedireply
|
||||||
// currently, the only reliable way to detect all toots etc. has the drawback that the same element could be processed multiple times
|
// currently, the only reliable way to detect all toots etc. has the drawback that the same element could be processed multiple times
|
||||||
// this will store already processed elements to compare prior to processing and will reset as soon as the site context changes
|
// this will store already processed elements to compare prior to processing and will reset as soon as the site context changes
|
||||||
var processed = []
|
var [processed, processedFollow, isProcessing] = [[],[],[]]
|
||||||
|
|
||||||
|
|
||||||
// =-=-=-=-==-=-=-=-==-=-=-=-=-
|
// =-=-=-=-==-=-=-=-==-=-=-=-=-
|
||||||
|
@ -832,6 +832,7 @@ async function processToots() {
|
||||||
initStyles([internalIdentifier, false])
|
initStyles([internalIdentifier, false])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
log("ALREADY PROCESSED")
|
||||||
// the toot is already in cache, so grab it
|
// the toot is already in cache, so grab it
|
||||||
var toot = processed[cacheIndex]
|
var toot = processed[cacheIndex]
|
||||||
// init stylings
|
// init stylings
|
||||||
|
@ -847,8 +848,18 @@ async function processToots() {
|
||||||
}
|
}
|
||||||
// One DOMNodeAppear to rule them all
|
// One DOMNodeAppear to rule them all
|
||||||
$(document).DOMNodeAppear(async function(e) {
|
$(document).DOMNodeAppear(async function(e) {
|
||||||
process($(e.target))
|
if (!isProcessing.includes($(e.target).get(0))) {
|
||||||
|
isProcessing.push($(e.target).get(0))
|
||||||
|
process($(e.target))
|
||||||
|
}
|
||||||
}, "div.status, div.detailed-status")
|
}, "div.status, div.detailed-status")
|
||||||
|
// try to find all existing elements (fixes some elements not being detected by DOMNodeAppear in rare cases, esp. v3)
|
||||||
|
$(document).find("div.status, div.detailed-status").each(function(){
|
||||||
|
if (!isProcessing.includes($(this).get(0))) {
|
||||||
|
isProcessing.push($(this).get(0))
|
||||||
|
process($(this))
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// main function to listen for the follow button pressed and open a new tab with the home instance
|
// main function to listen for the follow button pressed and open a new tab with the home instance
|
||||||
|
@ -892,55 +903,58 @@ async function processFollow() {
|
||||||
}
|
}
|
||||||
// do we have a full handle?
|
// do we have a full handle?
|
||||||
if (fullHandle) {
|
if (fullHandle) {
|
||||||
// yes, so resolve it to a user id on our homeinstance
|
if (!processedFollow.includes(fullHandle)) {
|
||||||
var resolvedHandle = await resolveHandleToHome(fullHandle)
|
// yes, so resolve it to a user id on our homeinstance
|
||||||
if (resolvedHandle) {
|
var resolvedHandle = await resolveHandleToHome(fullHandle)
|
||||||
// successfully resolved
|
if (resolvedHandle) {
|
||||||
// if showfollows is enabled...
|
processedFollow.push(fullHandle)
|
||||||
if (settings.fediact_showfollows) {
|
// successfully resolved
|
||||||
// ... then check if user is already following
|
// if showfollows is enabled...
|
||||||
var isFollowing = await isFollowingHomeInstance([resolvedHandle[0]])
|
if (settings.fediact_showfollows) {
|
||||||
// update button text and action if already following
|
// ... then check if user is already following
|
||||||
if (isFollowing[0]) {
|
var isFollowing = await isFollowingHomeInstance([resolvedHandle[0]])
|
||||||
$(el).text("Unfollow")
|
// update button text and action if already following
|
||||||
action = "unfollow"
|
if (isFollowing[0]) {
|
||||||
}
|
$(el).text("Unfollow")
|
||||||
}
|
action = "unfollow"
|
||||||
// single and double click handling (see toot processing for explanation, is the same basically)
|
|
||||||
var clicks = 0
|
|
||||||
var timer
|
|
||||||
$(el).on("click", async function(e) {
|
|
||||||
// prevent default and immediate propagation
|
|
||||||
e.preventDefault()
|
|
||||||
e.stopImmediatePropagation()
|
|
||||||
clicks++
|
|
||||||
if (clicks == 1) {
|
|
||||||
timer = setTimeout(async function() {
|
|
||||||
execFollow(resolvedHandle[0])
|
|
||||||
clicks = 0
|
|
||||||
}, 350)
|
|
||||||
} else {
|
|
||||||
clearTimeout(timer)
|
|
||||||
var done = await execFollow(resolvedHandle[0])
|
|
||||||
if (done) {
|
|
||||||
var saveText = $(el).text()
|
|
||||||
var redirectUrl = 'https://' + settings.fediact_homeinstance + '/@' + resolvedHandle[1]
|
|
||||||
$(el).text("Redirecting...")
|
|
||||||
setTimeout(function() {
|
|
||||||
redirectTo(redirectUrl)
|
|
||||||
$(el).text(saveText)
|
|
||||||
}, 1000)
|
|
||||||
} else {
|
|
||||||
log("Action failed.")
|
|
||||||
}
|
}
|
||||||
clicks = 0
|
|
||||||
}
|
}
|
||||||
}).on("dblclick", function(e) {
|
// single and double click handling (see toot processing for explanation, is the same basically)
|
||||||
e.preventDefault()
|
var clicks = 0
|
||||||
e.stopImmediatePropagation()
|
var timer
|
||||||
})
|
$(el).on("click", async function(e) {
|
||||||
} else {
|
// prevent default and immediate propagation
|
||||||
log("Could not resolve user home ID.")
|
e.preventDefault()
|
||||||
|
e.stopImmediatePropagation()
|
||||||
|
clicks++
|
||||||
|
if (clicks == 1) {
|
||||||
|
timer = setTimeout(async function() {
|
||||||
|
execFollow(resolvedHandle[0])
|
||||||
|
clicks = 0
|
||||||
|
}, 350)
|
||||||
|
} else {
|
||||||
|
clearTimeout(timer)
|
||||||
|
var done = await execFollow(resolvedHandle[0])
|
||||||
|
if (done) {
|
||||||
|
var saveText = $(el).text()
|
||||||
|
var redirectUrl = 'https://' + settings.fediact_homeinstance + '/@' + resolvedHandle[1]
|
||||||
|
$(el).text("Redirecting...")
|
||||||
|
setTimeout(function() {
|
||||||
|
redirectTo(redirectUrl)
|
||||||
|
$(el).text(saveText)
|
||||||
|
}, 1000)
|
||||||
|
} else {
|
||||||
|
log("Action failed.")
|
||||||
|
}
|
||||||
|
clicks = 0
|
||||||
|
}
|
||||||
|
}).on("dblclick", function(e) {
|
||||||
|
e.preventDefault()
|
||||||
|
e.stopImmediatePropagation()
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
log("Could not resolve user home ID.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -948,8 +962,18 @@ async function processFollow() {
|
||||||
var allFollowPaths = followButtonPaths.join(",")
|
var allFollowPaths = followButtonPaths.join(",")
|
||||||
// one domnodeappear to rule them all
|
// one domnodeappear to rule them all
|
||||||
$(document).DOMNodeAppear(async function(e) {
|
$(document).DOMNodeAppear(async function(e) {
|
||||||
process($(e.target))
|
if (!isProcessing.includes($(e.target).get(0))) {
|
||||||
|
isProcessing.push($(e.target).get(0))
|
||||||
|
process($(e.target))
|
||||||
|
}
|
||||||
}, allFollowPaths)
|
}, allFollowPaths)
|
||||||
|
// try to find all existing elements (fixes some elements not being detected by DOMNodeAppear in rare cases, esp. v3)
|
||||||
|
$(document).find(allFollowPaths).each(function(){
|
||||||
|
if (!isProcessing.includes($(this).get(0))) {
|
||||||
|
isProcessing.push($(this).get(0))
|
||||||
|
process($(this))
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1057,6 +1081,8 @@ async function backgroundProcessor() {
|
||||||
if (request.urlchanged) {
|
if (request.urlchanged) {
|
||||||
// reset already processed elements
|
// reset already processed elements
|
||||||
processed = []
|
processed = []
|
||||||
|
processedFollow = []
|
||||||
|
isProcessing = []
|
||||||
// rerun getSettings to keep mutes/blocks up to date while not reloading the page
|
// rerun getSettings to keep mutes/blocks up to date while not reloading the page
|
||||||
if (!await getSettings()) {
|
if (!await getSettings()) {
|
||||||
// but reload if settings are invalid
|
// but reload if settings are invalid
|
||||||
|
|
File diff suppressed because one or more lines are too long
Ładowanie…
Reference in New Issue