5 Commits

Author SHA1 Message Date
Josh Patra
1277750716 versioning stuff 2025-07-03 15:28:21 -04:00
Josh Patra
247a46d430 I'm stupid, the problem was resuming, not pausing 2025-07-03 15:14:19 -04:00
Josh Patra
703658335c version bump but still broken 2025-07-03 15:02:38 -04:00
Josh Patra
b2ed0fcb41 add deploy script 2025-07-03 14:49:52 -04:00
Josh Patra
3dfee251ec fix pause reset 2025-07-03 14:42:25 -04:00
3 changed files with 137 additions and 31 deletions

118
build.py Normal file
View File

@@ -0,0 +1,118 @@
import glob
import os
import re
import shutil
import tempfile
import zipfile
SCRIPT_NAME = os.path.basename(__file__)
TARGET_FILE = "manifest.json"
def zip_folder(output_name, folder, exclude_files, exclude_dirs):
with zipfile.ZipFile(output_name, "w", zipfile.ZIP_DEFLATED) as zipf:
for root, dirs, files in os.walk(folder):
dirs[:] = [
d
for d in dirs
if os.path.relpath(os.path.join(root, d), folder) not in exclude_dirs
]
for file in files:
rel_path = os.path.relpath(os.path.join(root, file), folder)
if (
file in exclude_files
or rel_path in exclude_files
or any(rel_path.startswith(ed + os.sep) for ed in exclude_dirs)
):
continue
zipf.write(os.path.join(root, file), arcname=rel_path)
def update_version_line(file_path, new_version):
with open(file_path, "r", encoding="utf-8") as f:
lines = f.readlines()
updated = False
for i, line in enumerate(lines):
match = re.match(r'\s*"version":\s*"([^"]+)"', line)
if match:
old_version = match.group(1)
lines[i] = re.sub(
r'"version":\s*".+?"', f'"version": "{new_version}"', line
)
updated = True
print(
f"🛠️ Changed version in {file_path} from {old_version}{new_version}"
)
break
if updated:
with open(file_path, "w", encoding="utf-8") as f:
f.writelines(lines)
else:
print(f"⚠️ No version line found in {file_path}.")
def main():
# Step 0: Remove all existing .xpi files upfront
xpi_files = glob.glob("*.xpi")
for f in xpi_files:
try:
os.remove(f)
print(f"🗑️ Removed existing archive: {f}")
except Exception as e:
print(f"⚠️ Failed to remove {f}: {e}")
base_version = input("Enter the new base version (e.g., 2.0.1): ").strip()
if not base_version:
print("❌ No version entered. Exiting.")
return
firefox_version = f"{base_version}.0"
current_dir = os.getcwd()
manifest_path = os.path.join(current_dir, TARGET_FILE)
# Step 1: Update manifest.json on disk to base_version
if os.path.exists(manifest_path):
update_version_line(manifest_path, base_version)
else:
print(f"{TARGET_FILE} not found. Aborting.")
return
# Step 2: Create videospeed-github.xpi (exclude script, .git, AND videospeed-github.xpi itself)
exclude_files = [SCRIPT_NAME, "videospeed-github.xpi"]
exclude_dirs = [".git"]
zip_folder("videospeed-github.xpi", current_dir, exclude_files, exclude_dirs)
print("✅ Created videospeed-github.xpi")
# Step 3: Re-scan for .xpi files after GitHub archive creation, exclude them for Firefox zip
current_xpi_files = set(glob.glob("*.xpi"))
exclude_temp_files = current_xpi_files.union({SCRIPT_NAME})
exclude_temp_dirs = set(exclude_dirs)
# Step 4: Create videospeed-firefox.xpi from temp folder with version bumped to .0
with tempfile.TemporaryDirectory() as temp_dir:
for item in os.listdir(current_dir):
if item in exclude_temp_files or item in exclude_temp_dirs:
continue
src = os.path.join(current_dir, item)
dst = os.path.join(temp_dir, item)
if os.path.isdir(src):
shutil.copytree(src, dst)
else:
shutil.copy2(src, dst)
temp_manifest = os.path.join(temp_dir, TARGET_FILE)
if os.path.exists(temp_manifest):
update_version_line(temp_manifest, firefox_version)
else:
print(f"⚠️ {TARGET_FILE} not found in temp folder.")
zip_folder(
"videospeed-firefox.xpi", temp_dir, exclude_files=[], exclude_dirs=[]
)
print("✅ Created videospeed-firefox.xpi")
if __name__ == "__main__":
main()

View File

@@ -174,42 +174,33 @@ function defineVideoController() {
target.playbackRate = storedSpeed;
this.div = this.initializeControls();
// FIXED: Make the controller visible for 5 seconds on startup
// Make the controller visible for 5 seconds on startup
runAction("blink", 5000, null, this.video);
// FIXED: Rewritten mediaEventAction to prevent speed reset on pause.
// Rewritten mediaEventAction to prevent speed reset on pause.
var mediaEventAction = function (event) {
// Subtitle Nudge logic is based on play/pause state.
// Handle subtitle nudging based on the event type first.
if (event.type === "play") {
this.startSubtitleNudge();
// Reapply the current speed to ensure it doesn't get reset
const currentSpeed = event.target.playbackRate;
if (currentSpeed !== 1.0) {
// Only reapply if it's not already at the correct speed
setTimeout(() => {
if (Math.abs(event.target.playbackRate - currentSpeed) > 0.01) {
event.target.playbackRate = currentSpeed;
}
}, 0);
}
} else if (event.type === "pause" || event.type === "ended") {
this.stopSubtitleNudge();
// On pause or end, DO NOT proceed to change speed.
// This is the key fix for the pause-resets-speed bug.
return;
}
// Speed restoration logic (for "play" and non-user "seeked" events)
// For seek events, don't mess with speed
if (event.type === "seeked" && isUserSeek) {
isUserSeek = false; // Reset flag
return; // Don't change speed on user-initiated seeks.
}
// Determine the speed that *should* be set, in case the site changed it.
let targetSpeed;
if (tc.settings.forceLastSavedSpeed) {
targetSpeed = tc.settings.lastSpeed;
} else if (tc.settings.rememberSpeed) {
targetSpeed = tc.settings.lastSpeed;
} else {
// Fallback to per-video speed or 1.0
targetSpeed = tc.settings.speeds[event.target.currentSrc] || 1.0;
}
// Only set the speed if the site has actually changed it.
// This avoids unnecessary "ratechange" events.
if (Math.abs(event.target.playbackRate - targetSpeed) > 0.01) {
setSpeed(event.target, targetSpeed);
isUserSeek = false;
return;
}
};
@@ -390,7 +381,7 @@ function defineVideoController() {
const r = parentEl.getRootNode();
const s = r && r.querySelector ? r.querySelector(".scrim") : null;
if (s) s.prepend(fragment);
else parentEl.insertBefore(fragment, pEl.firstChild);
else parentEl.insertBefore(fragment, parentEl.firstChild);
break;
default:
parentEl.insertBefore(fragment, parentEl.firstChild);
@@ -831,7 +822,6 @@ function pause(v) {
else v.pause();
}
// FIXED: Using the improved resetSpeed function for toggling
function resetSpeed(v, target, isFastKey = false) {
const videoId = v.currentSrc || v.src || "default";
const currentSpeed = v.playbackRate;
@@ -879,7 +869,6 @@ function jumpToMark(v) {
if (v.vsc && typeof v.vsc.mark === "number") v.currentTime = v.vsc.mark;
}
function handleDrag(video, e) {
/* ... Same original logic ... */
const c = video.vsc.div;
const sC = c.shadowRoot.querySelector("#controller");
var pE = c.parentElement;
@@ -911,7 +900,6 @@ function handleDrag(video, e) {
}
var timer = null;
function showController(controller) {
/* ... Same original logic ... */
if (!controller || typeof controller.classList === "undefined") return;
controller.classList.add("vsc-show");
if (timer) clearTimeout(timer);

View File

@@ -1,7 +1,7 @@
{
"name": "Video Speed Controller",
"short_name": "videospeed",
"version": "1.2.1",
"version": "1.4.1",
"manifest_version": 2,
"description": "Speed up, slow down, advance and rewind HTML5 audio/video with shortcuts",
"homepage_url": "https://github.com/SoPat712/videospeed",