Commit 61a97673 authored by Stefy Spora's avatar Stefy Spora

Fix context menu URL patterns and add URL validation

- Change context menu URL patterns from specific video/picture patterns to general FetLife pattern
- Add URL validation in click handlers to ensure actions only work on video/picture pages
- Support both direct URLs (/videos/ID, /pictures/ID) and username-based URLs (/{username}/videos/ID)
- Add user-friendly error messages when not on appropriate pages
- Maintain backward compatibility with existing functionality
- Improve user experience with clear feedback for incorrect page usage
parent 569b4dcb
......@@ -35,29 +35,20 @@ chrome.runtime.onInstalled.addListener(() => {
documentUrlPatterns: ['https://fetlife.com/*']
});
// Create privacy-specific context menu items for video/picture pages
// Create privacy-specific context menu items for all FetLife pages
// We'll check the URL in the click handler to determine if it's a video/picture page
chrome.contextMenus.create({
id: 'set-friends-only',
title: '👥 Set to Friends Only',
contexts: ['page'],
documentUrlPatterns: [
'https://fetlife.com/videos/*',
'https://fetlife.com/pictures/*',
'https://fetlife.com/*/videos/*',
'https://fetlife.com/*/pictures/*'
]
documentUrlPatterns: ['https://fetlife.com/*']
});
chrome.contextMenus.create({
id: 'set-all-fetlifers',
title: '🌐 Set to All Fetlifers',
contexts: ['page'],
documentUrlPatterns: [
'https://fetlife.com/videos/*',
'https://fetlife.com/pictures/*',
'https://fetlife.com/*/videos/*',
'https://fetlife.com/*/pictures/*'
]
documentUrlPatterns: ['https://fetlife.com/*']
});
console.log('FetLife Privacy Helper extension installed');
......@@ -120,6 +111,21 @@ chrome.contextMenus.onClicked.addListener(async (info, tab) => {
}
} else if (info.menuItemId === 'set-friends-only') {
try {
// Check if we're on a video or picture page
const url = tab.url;
const isVideoPage = /\/(?:[^\/]+\/)?videos\/\d+/.test(url);
const isPicturePage = /\/(?:[^\/]+\/)?pictures\/\d+/.test(url);
if (!isVideoPage && !isPicturePage) {
chrome.notifications.create({
type: 'basic',
iconUrl: 'icon48.png',
title: 'FetLife Privacy Helper',
message: 'Please navigate to a video or picture page first.'
});
return;
}
// Execute privacy update with friends_only setting
const results = await chrome.scripting.executeScript({
target: { tabId: tab.id },
......@@ -148,6 +154,21 @@ chrome.contextMenus.onClicked.addListener(async (info, tab) => {
}
} else if (info.menuItemId === 'set-all-fetlifers') {
try {
// Check if we're on a video or picture page
const url = tab.url;
const isVideoPage = /\/(?:[^\/]+\/)?videos\/\d+/.test(url);
const isPicturePage = /\/(?:[^\/]+\/)?pictures\/\d+/.test(url);
if (!isVideoPage && !isPicturePage) {
chrome.notifications.create({
type: 'basic',
iconUrl: 'icon48.png',
title: 'FetLife Privacy Helper',
message: 'Please navigate to a video or picture page first.'
});
return;
}
// Execute privacy update with all_fetlifers setting
const results = await chrome.scripting.executeScript({
target: { tabId: tab.id },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment