Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vanilla Audio: New dashboard support #1935

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions Extensions/vanilla_audio.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//* TITLE Vanilla Audio **//
//* VERSION 0.2.1 **//
//* VERSION 0.3.0 **//
//* DESCRIPTION Adds an alternative audio player to audio posts. **//
//* DETAILS This extension adds a native HTML5 audio player to every audio post, with an option for the default volume and the ability to loop the audio. **//
//* DEVELOPER akunohomu **//
Expand All @@ -26,13 +26,36 @@ XKit.extensions.vanilla_audio = new Object({
}
},

run: function() {
run: async function() {
"use strict";
this.running = true;

if (XKit.page.react) {
await XKit.css_map.getCssMap();
XKit.tools.add_css(".xkit-audio-player { display: block !important; margin: auto; }", "vanilla_audio");
XKit.post_listener.add("vanilla_audio", this.add_audio_react);
this.add_audio_react();
return;
}

XKit.post_listener.add("vanilla_audio", this.add_audio);
this.add_audio();
},

add_audio_react: function() {
"use strict";
let audiocontainer_classname = XKit.css_map.keyToClasses('nativePlayer')[0];
$(`.${audiocontainer_classname}`).not(".xkit-audio-added").each(function() {
var $this = $(this);
$this.addClass("xkit-audio-added");
$this.children().css("display", "none");
var hidden_player = $this.find("audio");
var xkit_player = $("<audio/>", { "controls": "controls", "class": "xkit-audio-player" }).appendTo($this);
xkit_player.prop("volume", XKit.extensions.vanilla_audio.preferences.default_volume.value);
hidden_player.find("source").clone().appendTo(xkit_player);
});
},

add_audio: function() {
"use strict";
$(".native-audio-container").not(".xkit-audio-added").each(function(index) {
Expand All @@ -52,6 +75,9 @@ XKit.extensions.vanilla_audio = new Object({
destroy: function() {
"use strict";
XKit.post_listener.remove("vanilla_audio");
if (XKit.page.react) {
$(".xkit-audio-added").children().css("display", "flex");
}
$(".xkit-audio-added").removeClass("xkit-audio-added");
$(".xkit-audio-player").remove();
this.running = false;
Expand Down