add setting for auto-action

tests v0.5.0
lartsch 2022-11-22 14:30:39 -05:00
rodzic b98f8b6fad
commit fdc0ea1b7b
3 zmienionych plików z 20 dodań i 12 usunięć

Wyświetl plik

@ -27,7 +27,8 @@ var settingsDefaults = {
fedifollow_mode: "blacklist",
fedifollow_whitelist: null,
fedifollow_blacklist: null,
fedifollow_target: "_blank"
fedifollow_target: "_blank",
fedifollow_autoaction: true
}
// fix for cross-browser storage api compatibility and other public vars
@ -194,15 +195,17 @@ async function processHomeInstance() {
if (response.accounts.length && !response.statuses.length) {
var redirect = location.protocol + "//" + location.hostname + "/@" + response.accounts[0].acct;
$('div#fedifollow').append("<p>Success!</p>");
$('div#fedifollow').append("<p>Attempting auto-follow...</p>");
var requestUrl = location.protocol + "//" + location.hostname + "/api/v1/accounts/" + response.accounts[0].id + "/follow";
var responseFollow = await makeRequest("POST",requestUrl,headers);
if (responseFollow) {
responseFollow = JSON.parse(responseFollow);
if (responseFollow.following || responseFollow.requested) {
$('div#fedifollow').append("<p>Success!</p>");
} else {
$('div#fedifollow').append("<p>Failed.</p>");
if (settings.fedifollow_autoaction) {
$('div#fedifollow').append("<p>Attempting auto-follow...</p>");
var requestUrl = location.protocol + "//" + location.hostname + "/api/v1/accounts/" + response.accounts[0].id + "/follow";
var responseFollow = await makeRequest("POST",requestUrl,headers);
if (responseFollow) {
responseFollow = JSON.parse(responseFollow);
if (responseFollow.following || responseFollow.requested) {
$('div#fedifollow').append("<p>Success!</p>");
} else {
$('div#fedifollow').append("<p>Failed.</p>");
}
}
}
} else if (!response.accounts.length && response.statuses.length) {
@ -214,7 +217,7 @@ async function processHomeInstance() {
"account": status.account.acct
}
var redirect = location.protocol + "//" + location.hostname + "/@" + statusData.account + "/" + statusData.id;
if (fediParamActionValue == "boost" || fediParamActionValue == "favourite") {
if (settings.fedifollow_autoaction && (fediParamActionValue == "boost" || fediParamActionValue == "favourite")) {
$('div#fedifollow').append("<p>Attempting auto-" + fediParamActionValue + "...</p>");
var actionRequest = location.protocol + "//" + location.hostname + "/api/v1/statuses/" + statusData.id + "/";
if (fediParamActionValue == "boost") {

Wyświetl plik

@ -15,6 +15,8 @@
<input type="text" id="homeinstance" name="homeinstance" placeholder="mastodon.social"><br>
<label for="alert">Alert on redirect:</label><br>
<input type="checkbox" id="alert" name="alert"><br>
<label for="alert">Auto-action:</label><br>
<input type="checkbox" id="autoaction" name="autoaction"><br>
<label for="target">Open in:</label><br>
<select name="target" id="target" selected="_blank">
<option id="target_blank" value="_blank">New tab</option>

Wyświetl plik

@ -6,7 +6,8 @@ var settings = {
fedifollow_mode: "blacklist",
fedifollow_whitelist: null,
fedifollow_blacklist: null,
fedifollow_target: "_blank"
fedifollow_target: "_blank",
fedifollow_autoaction: true
}
// fix for cross-browser storage api compatibility
@ -34,6 +35,7 @@ function popupTasks(settings) {
settings.fedifollow_whitelist = $("textarea#whitelist_content").val();
settings.fedifollow_blacklist = $("textarea#blacklist_content").val();
settings.fedifollow_target = $("select#target").val();
settings.fedifollow_autoaction = $("input#autoaction").is(':checked');
// write to storage
const waitForSaved = (browser || chrome).storage.local.set(settings);
// show saved indicator after successful save
@ -48,6 +50,7 @@ function popupTasks(settings) {
$("select#mode").val(settings.fedifollow_mode);
$("select#target").val(settings.fedifollow_target);
$("input#alert").prop('checked', settings.fedifollow_alert);
$("input#autoaction").prop('checked', settings.fedifollow_autoaction);
// both containers are hidden by default
if ($("select#mode").val() == "whitelist") {
$("div#whitelist_input").show();