Skip to content

Commit

Permalink
added new options, renamed options
Browse files Browse the repository at this point in the history
  • Loading branch information
lartsch committed Dec 15, 2022
1 parent 4c7b58c commit 1fab108
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 48 deletions.
2 changes: 1 addition & 1 deletion firefox/manifest.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
69 changes: 42 additions & 27 deletions src/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
}
Expand Down Expand Up @@ -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 = {
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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>")
}
}
}
Expand Down Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/inject.min.js

Large diffs are not rendered by default.

35 changes: 19 additions & 16 deletions src/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
8 changes: 7 additions & 1 deletion src/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/popup.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1fab108

Please sign in to comment.