check changelog
This commit is contained in:
parent
f64b5963e9
commit
ccc6603f88
6 changed files with 75 additions and 20 deletions
|
|
@ -5,7 +5,7 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
actix-web = "4"
|
||||
rust-discord-activity = { git = "https://github.com/AmokDev/rust-discord-activity", version = "0.3.1" }
|
||||
rust-discord-rpc = { git = "https://git.amok.dev/AmokDev/rust-discord-rpc", version = "0.3.3" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
{"episode":6,"season":1,"timestamps":[18000,2597000],"name":"Элементарно","image_url":"https://statichdrezka.ac/i/2020/12/17/xe6ea25038d76rc83x59z.jpeg"}
|
||||
{"episode":0,"season":0,"timestamps":[0, 0],"name":"name","image_url":"image_url"}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
use rust_discord_activity::{
|
||||
use rust_discord_rpc::{
|
||||
DiscordClient,
|
||||
Asset,
|
||||
Timestamp,
|
||||
|
|
@ -17,8 +17,13 @@ pub async fn start_presence() {
|
|||
let _ = client.connect();
|
||||
println!(":: Rich Presence started!");
|
||||
|
||||
|
||||
loop {
|
||||
if client.is_connected == false {
|
||||
println!(":: Reconnecting...");
|
||||
tokio::time::sleep(Duration::from_secs(5)).await;
|
||||
let _ = client.connect();
|
||||
continue;
|
||||
}
|
||||
let post_data = load_from_json();
|
||||
let mut episode: u8 = 0;
|
||||
let mut season: u8 = 0;
|
||||
|
|
@ -33,29 +38,41 @@ pub async fn start_presence() {
|
|||
image_url = data.image_url;
|
||||
}
|
||||
|
||||
let asset = Asset::new(Some(image_url), Some(String::from("#noWar")), None, None);
|
||||
let mut asset = Asset::new(Some(image_url.clone()), None, None, None);
|
||||
let now_in_millis = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis();
|
||||
let timestamp = Timestamp::new(Some(now_in_millis - timestamps[0]), Some(now_in_millis + (timestamps[1] - timestamps[0])));
|
||||
let mut activity = Activity::new();
|
||||
let mut activity_type = ActivityType::WATCHING;
|
||||
|
||||
let mut subtitle = format!("Сезон {season} Серия {episode}");
|
||||
if season == 0 && episode == 0 {
|
||||
subtitle = format!("Фильм");
|
||||
}
|
||||
if episode == 0 && timestamps[0] == 0 && timestamps[1] == 0 {
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
client.is_connected = false;
|
||||
continue;
|
||||
}
|
||||
if timestamps[0] == 1 && timestamps[1] == 1 {
|
||||
activity_type = ActivityType::COMPETING;
|
||||
asset = Asset::new(Some(image_url), Some(String::from("Paused")), None, None);
|
||||
}
|
||||
if timestamps[0] == 2 && timestamps[1] == 2 {
|
||||
activity_type = ActivityType::COMPETING;
|
||||
asset = Asset::new(Some(String::from("hdrezcord-logo")), None, None, None);
|
||||
name = String::from("Ничего не смотрит");
|
||||
subtitle = String::from("...");
|
||||
}
|
||||
// сорян за гкод, потом пофикшу
|
||||
activity
|
||||
.set_state(Some(subtitle).into())
|
||||
.set_activity_type(Some(ActivityType::WATCHING))
|
||||
.set_activity_type(Some(activity_type))
|
||||
.set_details(Some(name))
|
||||
.set_timestamps(Some(timestamp))
|
||||
.set_assets(Some(asset))
|
||||
.set_instance(Some(true));
|
||||
|
||||
let payload = Payload::new(EventName::Activity, EventData::Activity(activity));
|
||||
|
||||
if episode == 0 && timestamps[0] == 0 && timestamps[1] == 0 {
|
||||
continue;
|
||||
}
|
||||
|
||||
let _ = client.send_payload(payload);
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
}
|
||||
|
|
|
|||
40
content.js
40
content.js
|
|
@ -56,12 +56,32 @@ function get_timestamps() {
|
|||
return [0, 0];
|
||||
}
|
||||
|
||||
if (!get_timestamps.previousTimes) {
|
||||
get_timestamps.previousTimes = [];
|
||||
}
|
||||
|
||||
get_timestamps.previousTimes.push(currentTime);
|
||||
|
||||
if (get_timestamps.previousTimes.length > 3) {
|
||||
get_timestamps.previousTimes.shift();
|
||||
}
|
||||
|
||||
if (get_timestamps.previousTimes.length === 3 &&
|
||||
get_timestamps.previousTimes.every(val => val === currentTime)) {
|
||||
console.warn("currentTime repeated too many times");
|
||||
return [1, 1];
|
||||
}
|
||||
|
||||
return [timeToMilliseconds(currentTime), timeToMilliseconds(totalTime)];
|
||||
}
|
||||
|
||||
function get_name() {
|
||||
let element = document.querySelector('.b-post__title h1[itemprop="name"]');
|
||||
try {
|
||||
return element.textContent;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function get_image_url() {
|
||||
|
|
@ -73,7 +93,7 @@ if (window.location.href.includes("flymaterez.net")) {
|
|||
setInterval(async () => {
|
||||
try {
|
||||
chrome.storage.local.get(['pluginEnabled'], function(result) {
|
||||
if (result.pluginEnabled === true) {
|
||||
if (result.pluginEnabled === true && get_name() !== null) {
|
||||
chrome.runtime.sendMessage({
|
||||
type: "send_rpc_request",
|
||||
title: document.title,
|
||||
|
|
@ -84,12 +104,22 @@ if (window.location.href.includes("flymaterez.net")) {
|
|||
name: get_name(),
|
||||
image_url: get_image_url(),
|
||||
});
|
||||
}
|
||||
console.log(result.pluginEnabled);
|
||||
} else if (result.pluginEnabled === true && get_name() === null) {
|
||||
chrome.runtime.sendMessage({
|
||||
type: "send_rpc_request",
|
||||
title: document.title,
|
||||
url: window.location.href,
|
||||
episode: 0,
|
||||
season: 0,
|
||||
timestamps: [2, 2],
|
||||
name: "name",
|
||||
image_url: "image_url",
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.warn(error);
|
||||
// console.log(error);
|
||||
;
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
|
|
|||
14
popup.js
14
popup.js
|
|
@ -9,11 +9,21 @@ function edit_status() {
|
|||
if (result.pluginEnabled === true) {
|
||||
chrome.storage.local.set({ pluginEnabled: false });
|
||||
plugin_status.innerHTML = "Plugin is disabled";
|
||||
chrome.runtime.sendMessage({
|
||||
type: "send_rpc_request",
|
||||
title: document.title,
|
||||
url: window.location.href,
|
||||
episode: 0,
|
||||
season: 0,
|
||||
timestamps: [0, 0],
|
||||
name: "name",
|
||||
image_url: "image_url",
|
||||
});
|
||||
} else if (result.pluginEnabled === false) {
|
||||
chrome.storage.local.set({ pluginEnabled: true });
|
||||
plugin_status.innerHTML = "Plugin is enabled";
|
||||
}
|
||||
console.log(result.pluginEnabled);
|
||||
// console.log(result.pluginEnabled);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -30,7 +40,7 @@ function get_status() {
|
|||
} else if (result.pluginEnabled === false) {
|
||||
plugin_status.innerHTML = "Plugin is disabled";
|
||||
}
|
||||
console.log(result.pluginEnabled);
|
||||
// console.log(result.pluginEnabled);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ async function send_rpc_request(data) {
|
|||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
console.log(response.type)
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
}
|
||||
|
|
@ -27,7 +26,6 @@ chrome.runtime.onMessage.addListener(
|
|||
name: request.name,
|
||||
image_url: request.image_url
|
||||
})
|
||||
console.log(request.episode, request.season, request.timestamps)
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue