added new options, renamed options

pull/14/head
lartsch 2022-12-14 19:23:31 -05:00
rodzic 4c7b58ccd9
commit 1fab1087ca
7 zmienionych plików z 72 dodań i 48 usunięć

Wyświetl plik

@ -1,6 +1,6 @@
{
"name": "FediAct",
"version": "0.9.7",
"version": "0.9.7.1",
"description": "Simplifies interactions on other Mastodon instances than your own. Visit https://github.com/lartsch/FediAct for more.",
"manifest_version": 2,
"content_scripts": [

Wyświetl plik

@ -1,6 +1,6 @@
{
"name": "FediAct",
"version": "0.9.7",
"version": "0.9.7.1",
"description": "Simplifies interactions on other Mastodon instances than your own. Visit https://github.com/lartsch/FediAct for more.",
"manifest_version": 3,
"content_scripts": [

Wyświetl plik

@ -32,6 +32,8 @@ const settingsDefaults = {
fediact_redirects: true,
fediact_enabledelay: true,
fediact_hidemuted: false,
fediact_runifloggedin: false,
fediact_showtoot: true,
fediact_mutesblocks: [],
fediact_domainblocks: []
}
@ -643,7 +645,7 @@ async function processToots() {
var bookmarkButton = $(el).find("button:has(i.fa-bookmark)").first()
var replyButton = $(el).find("button:has(i.fa-reply), button:has(i.fa-reply-all), a.icon-button:has(i.fa-reply), a.icon-button:has(i.fa-reply-all)").first()
var voteButton = $(el).find("div.poll button").first()
// handles process when a toot button is clicked
// handles process when a vote button is clicked
async function pollAction(id, redirect, e) {
if (settings.fediact_autoaction) {
var pollData = {
@ -662,6 +664,7 @@ async function processToots() {
$(pollDiv).find("ul").replaceWith("<p style='font-style: italic'><a style='font-weight:bold; color:orange' href='" + redirect + "' target='" + settings.fediact_target + "'>View the results</a> on your home instance.<p>")
if (cacheIndex) {
processed[cacheIndex][9] = !processed[cacheIndex][9]
processed[cacheIndex][9] = true
}
}
return result
@ -676,6 +679,10 @@ async function processToots() {
// resolve url on home instance to get local toot/author identifiers and toot status
var actionExecuted = await executeAction(id, action, null)
if (actionExecuted) {
if (cacheIndex) {
// set interacted to true
processed[cacheIndex][10] = true
}
// if the action was successfully executed, update the element styles
if (action == "boost" || action == "unboost") {
// toggle inline css styles
@ -719,32 +726,34 @@ async function processToots() {
// yes, then add the Unresolved indicator
$("<span class='feditriggered' style='color: orange; padding-right: 10px; padding-left: 10px'>Unresolved</span>").insertAfter($(favButton))
} else {
// otherwise start processing button styles
// otherwise start processing button styles (if enabled OR if the toot was already interacted with, to restore the state while still on the same page)
// first enable the bookmark button (is disabled on external instances)
$(bookmarkButton).removeClass("disabled").removeAttr("disabled")
$(voteButton).removeAttr("disabled")
// set the toot buttons to active, depending on the state of the resolved toot and if the element already has the active class
if (tootdata[4]) {
if (!$(favButton).hasClass("fediactive")) {
toggleInlineCss($(favButton),[["color","!remove","rgb(202, 143, 4)"]], "fediactive")
toggleInlineCss($(favButton).find("i"),[["animation","spring-rotate-out 1s linear","spring-rotate-in 1s linear"]], "fediactive")
if (settings.fediact_showtoot || tootdata[10]) {
// set the toot buttons to active, depending on the state of the resolved toot and if the element already has the active class
if (tootdata[4]) {
if (!$(favButton).hasClass("fediactive")) {
toggleInlineCss($(favButton),[["color","!remove","rgb(202, 143, 4)"]], "fediactive")
toggleInlineCss($(favButton).find("i"),[["animation","spring-rotate-out 1s linear","spring-rotate-in 1s linear"]], "fediactive")
}
}
}
// repeat for other buttons
if (tootdata[3]) {
if (!$(boostButton).find("i.fediactive").length) {
toggleInlineCss($(boostButton),[["color","!remove","rgb(140, 141, 255)"]], "fediactive")
toggleInlineCss($(boostButton).find("i"),[["transition-duration", "!remove", "0.9s"],["background-position", "!remove", "0px 100%"]], "fediactive")
// repeat for other buttons
if (tootdata[3]) {
if (!$(boostButton).find("i.fediactive").length) {
toggleInlineCss($(boostButton),[["color","!remove","rgb(140, 141, 255)"]], "fediactive")
toggleInlineCss($(boostButton).find("i"),[["transition-duration", "!remove", "0.9s"],["background-position", "!remove", "0px 100%"]], "fediactive")
}
}
}
if (tootdata[5]) {
if (!$(bookmarkButton).hasClass("fediactive")) {
toggleInlineCss($(bookmarkButton),[["color","!remove","rgb(255, 80, 80)"]], "fediactive")
if (tootdata[5]) {
if (!$(bookmarkButton).hasClass("fediactive")) {
toggleInlineCss($(bookmarkButton),[["color","!remove","rgb(255, 80, 80)"]], "fediactive")
}
}
if (tootdata[9]) {
$(voteButton).hide()
$(voteButton).closest("div.poll").find("ul").replaceWith("<p style='font-style: italic'><a style='font-weight:bold; color:orange' href='" + tootdata[6] + "' target='" + settings.fediact_target + "'>View the results</a> on your home instance.<p>")
}
}
if (tootdata[9]) {
$(voteButton).hide()
$(voteButton).closest("div.poll").find("ul").replaceWith("<p style='font-style: italic'><a style='font-weight:bold; color:orange' href='" + tootdata[6] + "' target='" + settings.fediact_target + "'>View the results</a> on your home instance.<p>")
}
}
}
@ -899,7 +908,8 @@ async function processToots() {
// set the redirect to home instance URL in @ format
var redirectUrl = 'https://' + settings.fediact_homeinstance + "/@" + resolvedToot[0] + "/" + resolvedToot[1]
// prepare the cache entry / toot data entry
var fullEntry = [internalIdentifier, ...resolvedToot, redirectUrl, true, ...poll]
var fullEntry = [internalIdentifier, ...resolvedToot, redirectUrl, true, ...poll, false]
// 0: internal identifier; 1: toot home acct / false 2: toot home id 3: toot reblogged 4: toot favourited 5: toot bookmarked 6: redirect url 7: ??? crap! 8: poll id / false 9: poll voted 10: interacted
}
}
}
@ -1166,14 +1176,19 @@ async function checkSite() {
} else {
settings.fediact_exturi = uri
}
if (await isLoggedIn()) {
log("Already logged in to this external instance.")
} else {
return true
if (!settings.fediact_runifloggedin) {
if (await isLoggedIn()) {
log("Already logged in to this external instance.")
return false
}
}
} else {
return false
}
} else {
return false
}
return false
return true
}
async function backgroundProcessor() {

2
src/inject.min.js vendored

File diff suppressed because one or more lines are too long

Wyświetl plik

@ -16,48 +16,51 @@
<script src="lib/jquery-3.6.1.min.js"></script>
<script src="popup.min.js"></script>
</head>
<body style="min-width: 300px">
<body style="min-width: 350px; font-size:12px">
<div id="mhi-wrapper">
<div id="mhi-containers">
<form id="fediact-settings">
<p><b>General</b></p>
<label class="pad" for="homeinstance">Home instance (make sure you are logged in):</label>
<p><b>Home instance</b></p>
<label class="pad" for="homeinstance">Make sure you are logged in to the instance you set here:</label>
<input type="text" id="homeinstance" name="homeinstance" placeholder="example.social"><br>
<p><b>Redirect settings</b></p>
<input type="checkbox" id="redirects" name="redirects">
<label for="redirects">Enable</label><br>
<input type="checkbox" id="alert" name="alert">
<label for="alert">Alert on redirect</label><br>
<label style="padding-right: 5px" for="target">Open in</label>
<label for="alert">Prompt</label><br>
<label style="padding-right: 5px" for="target">Open in...</label>
<select style="margin-top: 5px;" name="target" id="target" selected="_blank">
<option id="target_blank" value="_blank">New tab</option>
<option id="target_self" value="_self">Same tab</option>
</select><br>
<p><b>Other</b></p>
<input type="checkbox" id="autoaction" name="autoaction">
<label for="autoaction">Auto-action</label><br>
<label for="autoaction">Actions</label><br>
<input type="checkbox" id="showfollows" name="showfollows">
<label for="showfollows">Show external follows</label><br>
<label for="showfollows">Show follows</label><br>
<input type="checkbox" id="showtoot" name="showtoot">
<label for="showtoot">Show toot state</label><br>
<input type="checkbox" id="hidemuted" name="hidemuted">
<label for="hidemuted">Hide muted</label><br>
<label for="hidemuted">Hide muted/blocked</label><br>
<input type="checkbox" id="delay" name="delay">
<label for="delay">Enable API delay</label><br>
<label for="delay">API delay</label><br>
<p><b>Mode</b></p>
<select name="mode" id="mode" selected="blacklist">
<option id="blacklist" value="blacklist">All (with blacklist)</option>
<input type="checkbox" id="runifloggedin" name="runifloggedin">
<label for="runifloggedin">Run if logged in</label><br>
<label style="padding-right: 5px" for="mode">Use...</label>
<select style="margin-top: 5px;" name="mode" id="mode" selected="blacklist">
<option id="blacklist" value="blacklist">Blacklist</option>
<option id="whitelist" value="whitelist">Whitelist</option>
</select><br>
<div class="hide" id="blacklist_input">
<label for="blacklist_content">Blacklist:</label><br>
<div style="margin-top: 5px;" class="hide" id="blacklist_input">
<textarea id="blacklist_content" name="blacklist_content" placeholder="example.social&#10;example2.social"></textarea><br>
</div>
<div class="hide" id="whitelist_input">
<label for="whitelist_content">Whitelist:</label><br>
<div style="margin-top: 5px;" class="hide" id="whitelist_input">
<textarea id="whitelist_content" name="whitelist_content" placeholder="example.social&#10;example2.social"></textarea><br>
</div><br>
<input type="submit" value="Submit">
<span id="indicator" style="display:none">Settings saved!</span>
<br><br><span>Made by <a target="_blank" href="https://github.com/lartsch">github.com/lartsch</a></span>
<br><br><span>Information and help at <a target="_blank" href="https://github.com/lartsch/FediAct">github.com/lartsch/FediAct</a></span><br>
</form>
</div>
</div>

Wyświetl plik

@ -11,7 +11,9 @@ const settingsDefaults = {
fediact_showfollows: true,
fediact_redirects: true,
fediact_enabledelay: true,
fediact_hidemuted: false
fediact_hidemuted: false,
fediact_runifloggedin: false,
fediact_showtoot: true
}
// fix for cross-browser storage api compatibility
@ -49,6 +51,8 @@ function popupTasks() {
settings.fediact_redirects = $("input#redirects").is(':checked')
settings.fediact_enabledelay = $("input#delay").is(':checked')
settings.fediact_hidemuted = $("input#hidemuted").is(':checked')
settings.fediact_runifloggedin = $("input#runifloggedin").is(':checked')
settings.fediact_showtoot = $("input#showtoot").is(':checked')
// write to storage
try {
await (browser || chrome).storage.local.set(settings)
@ -73,6 +77,8 @@ function popupTasks() {
$("input#redirects").prop('checked', settings.fediact_redirects)
$("input#delay").prop('checked', settings.fediact_enabledelay)
$("input#hidemuted").prop('checked', settings.fediact_hidemuted)
$("input#runifloggedin").prop('checked', settings.fediact_runifloggedin)
$("input#showtoot").prop('checked', settings.fediact_showtoot)
// both containers are hidden by default
if ($("select#mode").val() == "whitelist") {
$("div#whitelist_input").show()

2
src/popup.min.js vendored
Wyświetl plik

@ -1 +1 @@
const t={fediact_homeinstance:null,fediact_alert:!1,fediact_mode:"blacklist",fediact_whitelist:null,fediact_blacklist:null,fediact_target:"_self",fediact_autoaction:!0,fediact_showfollows:!0,fediact_redirects:!0,fediact_enabledelay:!0,fediact_hidemuted:!1};var browser,chrome,a;const i=!0,c="[FediAct]";function d(t){i&&console.log(c+" "+t)}function n(){async function i(){a.fediact_homeinstance=$("input#homeinstance").val().trim(),a.fediact_alert=$("input#alert").is(":checked"),a.fediact_mode=$("select#mode").val(),a.fediact_whitelist=$("textarea#whitelist_content").val(),a.fediact_blacklist=$("textarea#blacklist_content").val(),a.fediact_target=$("select#target").val(),a.fediact_autoaction=$("input#autoaction").is(":checked"),a.fediact_showfollows=$("input#showfollows").is(":checked"),a.fediact_redirects=$("input#redirects").is(":checked"),a.fediact_enabledelay=$("input#delay").is(":checked"),a.fediact_hidemuted=$("input#hidemuted").is(":checked");try{await(browser||chrome).storage.local.set(a)}catch{return d(e),!1}$("span#indicator").show(),setTimeout(function(){$("span#indicator").hide()},1500)}$(document).ready(function(){$("input#homeinstance").val(a.fediact_homeinstance),$("textarea#blacklist_content").val(a.fediact_blacklist),$("textarea#whitelist_content").val(a.fediact_whitelist),$("select#mode").val(a.fediact_mode),$("select#target").val(a.fediact_target),$("input#alert").prop("checked",a.fediact_alert),$("input#autoaction").prop("checked",a.fediact_autoaction),$("input#showfollows").prop("checked",a.fediact_showfollows),$("input#redirects").prop("checked",a.fediact_redirects),$("input#delay").prop("checked",a.fediact_enabledelay),$("input#hidemuted").prop("checked",a.fediact_hidemuted),("whitelist"==$("select#mode").val()?$("div#whitelist_input"):$("div#blacklist_input")).show(),$("select#mode").change(function(){("whitelist"==$("select#mode").val()?($("div#blacklist_input").hide(),$("div#whitelist_input")):($("div#whitelist_input").hide(),$("div#blacklist_input"))).show()}),$("form#fediact-settings").on("submit",async function(t){t.preventDefault(),i();try{await chrome.runtime.sendMessage({updatedsettings:!0})}catch(t){d(t)}})})}async function l(){try{a=await(browser||chrome).storage.local.get(t)}catch(t){return d(t),!1}a&&n()}l();
const t={fediact_homeinstance:null,fediact_alert:!1,fediact_mode:"blacklist",fediact_whitelist:null,fediact_blacklist:null,fediact_target:"_self",fediact_autoaction:!0,fediact_showfollows:!0,fediact_redirects:!0,fediact_enabledelay:!0,fediact_hidemuted:!1,fediact_runifloggedin:!1,fediact_showtoot:!0};var browser,chrome,c;const i=!0,a="[FediAct]";function d(t){i&&console.log(a+" "+t)}function n(){async function i(){c.fediact_homeinstance=$("input#homeinstance").val().trim(),c.fediact_alert=$("input#alert").is(":checked"),c.fediact_mode=$("select#mode").val(),c.fediact_whitelist=$("textarea#whitelist_content").val(),c.fediact_blacklist=$("textarea#blacklist_content").val(),c.fediact_target=$("select#target").val(),c.fediact_autoaction=$("input#autoaction").is(":checked"),c.fediact_showfollows=$("input#showfollows").is(":checked"),c.fediact_redirects=$("input#redirects").is(":checked"),c.fediact_enabledelay=$("input#delay").is(":checked"),c.fediact_hidemuted=$("input#hidemuted").is(":checked"),c.fediact_runifloggedin=$("input#runifloggedin").is(":checked"),c.fediact_showtoot=$("input#showtoot").is(":checked");try{await(browser||chrome).storage.local.set(c)}catch{return d(e),!1}$("span#indicator").show(),setTimeout(function(){$("span#indicator").hide()},1500)}$(document).ready(function(){$("input#homeinstance").val(c.fediact_homeinstance),$("textarea#blacklist_content").val(c.fediact_blacklist),$("textarea#whitelist_content").val(c.fediact_whitelist),$("select#mode").val(c.fediact_mode),$("select#target").val(c.fediact_target),$("input#alert").prop("checked",c.fediact_alert),$("input#autoaction").prop("checked",c.fediact_autoaction),$("input#showfollows").prop("checked",c.fediact_showfollows),$("input#redirects").prop("checked",c.fediact_redirects),$("input#delay").prop("checked",c.fediact_enabledelay),$("input#hidemuted").prop("checked",c.fediact_hidemuted),$("input#runifloggedin").prop("checked",c.fediact_runifloggedin),$("input#showtoot").prop("checked",c.fediact_showtoot),("whitelist"==$("select#mode").val()?$("div#whitelist_input"):$("div#blacklist_input")).show(),$("select#mode").change(function(){("whitelist"==$("select#mode").val()?($("div#blacklist_input").hide(),$("div#whitelist_input")):($("div#whitelist_input").hide(),$("div#blacklist_input"))).show()}),$("form#fediact-settings").on("submit",async function(t){t.preventDefault(),i();try{await chrome.runtime.sendMessage({updatedsettings:!0})}catch(t){d(t)}})})}async function o(){try{c=await(browser||chrome).storage.local.get(t)}catch(t){return d(t),!1}c&&n()}o();