God bless you all
God bless you all
document.addEventListener("DOMContentLoaded", function () {
waitForPublisherAndInject();
const btn = document.getElementById("tiktokBtn");
if (btn) {
btn.addEventListener("click", function () {
openTikTokModal();
checkTikTokStatus();
});
}
});
function openTikTokModal() {
document.getElementById("tiktokModal").style.display = "block";
}
function closeTikTokModal() {
document.getElementById("tiktokModal").style.display = "none";
}
function checkTikTokStatus() {
fetch("tiktok-check.php")
.then(res => res.json())
.then(data => {
let statusDiv = document.getElementById("tiktokStatus");
let actionDiv = document.getElementById("tiktokActions");
if (data.connected) {
statusDiv.innerHTML = "โ
Connected to TikTok";
actionDiv.innerHTML = `
`;
} else {
statusDiv.innerHTML = "โ Not connected";
actionDiv.innerHTML = `
`;
}
});
}
function connectTikTok() {
window.location.href = "tiktok-login.php";
}
function waitForPublisherAndInject() {
const observer = new MutationObserver(() => {
const container = document.querySelector(".publisher-footer");
if (container && !document.getElementById("tiktokBtn")) {
injectTikTokButton();
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
}
function injectTikTokButton() {
const container = document.querySelector(".publisher-footer");
if (!container) return;
const btn = document.createElement("button");
btn.type = "button";
btn.className = "btn btn-danger btn-mat";
btn.id = "tiktokBtn";
btn.innerText = "Post to TikTok";
const postBtn = container.querySelector(".js_publisher");
if (postBtn) {
postBtn.insertAdjacentElement("afterend", btn);
} else {
container.appendChild(btn);
}
}