Skip to content

Commit

Permalink
reblog,favourites mastodon
Browse files Browse the repository at this point in the history
  • Loading branch information
strukturart committed Aug 12, 2023
1 parent 061ba32 commit 70e4df1
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 54 deletions.
90 changes: 51 additions & 39 deletions application/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,8 @@ let rss_fetcher = function (
let item_link = "";
let item_title = "";
let item_type = "";
let item_media_type = "";

let item_date_unix = "";

let item_media = "rss";
Expand Down Expand Up @@ -684,21 +686,23 @@ let rss_fetcher = function (
.querySelector("enclosure")
.getAttribute("url");
if (el[i].querySelector("enclosure").getAttribute("type"))
item_type = el[i].querySelector("enclosure").getAttribute("type");
item_media_type = el[i]
.querySelector("enclosure")
.getAttribute("type");

if (
item_type == "audio/mpeg" ||
item_type == "audio/aac" ||
item_type == "audio/x-mpeg" ||
item_type == "audio/mp3" ||
item_type == "audio/x-m4a"
item_media_type == "audio/mpeg" ||
item_media_type == "audio/aac" ||
item_media_type == "audio/x-mpeg" ||
item_media_type == "audio/mp3" ||
item_media_type == "audio/x-m4a"
) {
item_media = "audio";
}

if (
item_type == "video/mp4" ||
item_type == "application/x-mpegurl"
item_media_type == "video/mp4" ||
item_media_type == "application/x-mpegurl"
) {
item_media = "video";
item_video_url = el[i]
Expand Down Expand Up @@ -805,7 +809,7 @@ let rss_fetcher = function (
item_title = "";
item_type = "";
item_date_unix = "";

item_media_type = "";
item_media = "rss";
item_duration = "";
item_filesize = "";
Expand Down Expand Up @@ -878,21 +882,23 @@ let rss_fetcher = function (
typeof el[i].querySelector("enclosure").getAttribute("type") !=
undefined
)
item_type = el[i].querySelector("enclosure").getAttribute("type");
item_media_type = el[i]
.querySelector("enclosure")
.getAttribute("type");

if (
item_type == "audio/mpeg" ||
item_type == "audio/aac" ||
item_type == "audio/x-mpeg" ||
item_type == "audio/mp3" ||
item_type == "audio/x-m4a"
item_media_type == "audio/mpeg" ||
item_media_type == "audio/aac" ||
item_media_type == "audio/x-mpeg" ||
item_media_type == "audio/mp3" ||
item_media_type == "audio/x-m4a"
) {
item_media = "audio";
}

if (
item_type == "video/mp4" ||
item_type == "application/x-mpegurl"
item_media_type == "video/mp4" ||
item_media_type == "application/x-mpegurl"
) {
item_media = "video";
item_video_url = el[i]
Expand Down Expand Up @@ -1462,7 +1468,7 @@ function nav_panels(left_right) {
//TABINDEX NAVIGATION
///////////

function nav(move) {
let nav = function (move) {
// Setup siblings array and get the first sibling
let siblings = [];

Expand All @@ -1482,8 +1488,6 @@ function nav(move) {
siblings.push(items[i]);
}

console.log(siblings);

if (move == "+1") {
tab_index++;

Expand Down Expand Up @@ -1519,7 +1523,7 @@ function nav(move) {
top: elY - window.innerHeight / 2,
behavior: "smooth",
});
}
};

//navigation between channels into channels view
let channel_navigation = function (direction) {
Expand Down Expand Up @@ -1602,7 +1606,6 @@ let show_article = function () {
detectURLs();
status.active_audio_element_id =
document.activeElement.getAttribute("data-id");
alert(status.active_audio_element_id);
} catch (e) {}

status.window_status = "single-article";
Expand Down Expand Up @@ -1658,7 +1661,8 @@ let show_article = function () {

if (
document.activeElement.getAttribute("data-media") == "rss" ||
document.activeElement.getAttribute("data-media") == "mastodon"
document.activeElement.getAttribute("data-media") == "mastodon" ||
document.activeElement.getAttribute("data-type") == "mastodon"
) {
bottom_bar(
"<img src='assets/icons/list.svg'>",
Expand Down Expand Up @@ -2080,15 +2084,22 @@ let start_options = function () {
}

if (document.activeElement.getAttribute("data-function") == "reblog") {
reblog(
localStorage.getItem("mastodon_server"),
status.active_audio_element_id
)
reblog(localStorage.getItem("mastodon_server"), status.active_element_id)
.then((data) => {
side_toaster("yeah", 20000);
side_toaster("status shared", 2000);
})
.catch((error) => {
side_toaster("error", 20000);
side_toaster(error, 2000);
});
}

if (document.activeElement.getAttribute("data-function") == "favourite") {
favourite(localStorage.getItem("mastodon_server"), status.active_element_id)
.then((data) => {
side_toaster("status favourites", 2000);
})
.catch((error) => {
side_toaster(error, 2000);
});
}

Expand Down Expand Up @@ -2384,7 +2395,6 @@ try {

request.onsuccess = function () {
this.result.forEach(function (alarm) {
//alert("alarm: " + alarm.date);
if (dayjs(alarm.date).isAfter(dayjs()) == true && action == true) {
action = false;
}
Expand Down Expand Up @@ -2603,7 +2613,7 @@ function shortpress_action(param) {
m +
"/oauth/authorize?client_id=" +
cred.clientId +
"&scope=read&redirect_uri=" +
"&scope=read+write&redirect_uri=" +
cred.redirect +
"&response_type=code";
window.open(url);
Expand All @@ -2616,16 +2626,15 @@ function shortpress_action(param) {
document.activeElement.getAttribute("data-function") ==
"mastodon-disconnect"
) {
document.getElementById("mastodon-server").value = "";
localStorage.removeItem("mastodon_server");
localStorage.removeItem("oauth_auth");
document.querySelector("input#mastodon-server").readOnly = false;
document.querySelector("[data-function='mastodon-disconnect']").value =
"connect";


document.querySelector("#mastodon-label").innerText = "-";
document.querySelector(".mastodon-connect-button") ="connect"
document.querySelector(".mastodon-connect-button").setAttribute("data-function","mastodon-connect")
side_toaster("account removed", 3000);
document.activeElement.setAttribute("data-function") ==
"mastodon-connect";
}

break;
Expand Down Expand Up @@ -2788,12 +2797,15 @@ function shortpress_action(param) {
play_podcast(document.activeElement.getAttribute("data-link"));
break;
}
/*
if (status.window_status == "single-article") {

if (
status.window_status == "single-article" &&
document.activeElement.getAttribute("data-media") == "youtube"
) {
open_url();
break;
}
*/

if (
document.activeElement.getAttribute("data-media") == "rss" ||
document.activeElement.getAttribute("data-media") == "mastodon"
Expand Down
14 changes: 0 additions & 14 deletions application/assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -936,20 +936,6 @@ div#progress-bar div {
background: var(--color-six);
}

article.view > div {
background: white;
color: black;
display: block;
font-style: "normal";
}

article.view {
background: red;
color: black;
display: block;
font-style: "normal";
}

/*
SETTINGS
*/
Expand Down
31 changes: 31 additions & 0 deletions application/assets/js/mastodon.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,37 @@ export let reblog = (url, id) => {

return new Promise((resolve, reject) => {
fetch(url + "/api/v1/statuses/" + id + "/reblog", {
method: "POST",
headers: w,
})
.then((response) => {
if (!response.ok) {
console.log("Network response was not OK");
reject(new Error("Network response was not OK"));
}
return response.json();
})
.then((data) => {
resolve(data);
})
.catch((error) => {
reject(error);
});
});
};

export let favourite = (url, id) => {
let a = JSON.parse(localStorage.getItem("oauth_auth"));
let accessToken = a.access_token;

let w = {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
};

return new Promise((resolve, reject) => {
fetch(url + "/api/v1/statuses/" + id + "/favourite", {
method: "POST",
headers: w,
})
.then((response) => {
Expand Down
4 changes: 3 additions & 1 deletion application/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ <h2>Options</h2>
<div class="item width-100" tabindex="0" data-function="">share</div>
<div class="item width-100" tabindex="1" data-function="">open in browser</div>
<div class="item width-100 mastodon" tabindex="2" data-function="reblog">reblog</div>
<div class="item width-100 mastodon" tabindex="3" data-function="favourite">favourite</div>


</div>

Expand Down Expand Up @@ -288,7 +290,7 @@ <h2>Number of episodes</h2>
<script id="template" type="x-tmpl-mustache">

{{#data}}
<article tabIndex={{index}} class="channels item" data-media="{{media}}" data-read="{{read}}" data-listened="{{listened}}" data-startlistened="{{start_listened}}" data-order="{{dateunix}}" data-youtube-id="{{youtube_id}}" data-video-url="{{video_url}}" data-recently="{{recently_order}}" data-mastodon-replies="{{replies_count}}" data-mastodon-reblog="{{reblogs_count}}" data-mastodon-favourites="{{favourites_count}}" data-category="{{category}} {{recently_played}} all" data-id="{{cid}}" data-channel="{{channel}}" data-link="{{link}}" data-youtube-id="{{id}}" data-audio-type="{{type}}" data-title="{{title}}" data-image="{{image}}">
<article tabIndex={{index}} class="channels item" data-media="{{media}}" data-read="{{read}}" data-type="{{type}}" data-listened="{{listened}}" data-startlistened="{{start_listened}}" data-order="{{dateunix}}" data-youtube-id="{{youtube_id}}" data-video-url="{{video_url}}" data-recently="{{recently_order}}" data-mastodon-replies="{{replies_count}}" data-mastodon-reblog="{{reblogs_count}}" data-mastodon-favourites="{{favourites_count}}" data-category="{{category}} {{recently_played}} all" data-id="{{cid}}" data-channel="{{channel}}" data-link="{{link}}" data-youtube-id="{{id}}" data-audio-type="{{type}}" data-title="{{title}}" data-image="{{image}}">
<div class="flex grid-col-10 icon-bar">
<div class="podcast-icon"><img src="assets/icons/podcast.png"></div>
<div class="youtube-icon"><img src="assets/icons/youtube.png"></div>
Expand Down

0 comments on commit 70e4df1

Please sign in to comment.