From 00c5a876891f14074ad5d951e8b5b98ad99e0bbc Mon Sep 17 00:00:00 2001 From: shinigami-eyes <43276258+shinigami-eyes@users.noreply.github.com> Date: Sun, 13 Jan 2019 18:25:47 +0100 Subject: [PATCH] Make sure the user doesn't mark URL types that do not represent a user --- extension/background.js | 61 +++++++++++++++++++++++++++++++++++++++++ extension/content.js | 8 ++++-- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/extension/background.js b/extension/background.js index fc089d9..1e2bde0 100644 --- a/extension/background.js +++ b/extension/background.js @@ -148,6 +148,64 @@ function openHelp() { }) } +var badIdentifiers = {}; +[ + 'facebook.com/a', + 'facebook.com/ad_campaign', + 'facebook.com/ads', + 'facebook.com/bookmarks', + 'facebook.com/buddylist.php', + 'facebook.com/bugnub', + 'facebook.com/comment', + 'facebook.com/composer', + 'facebook.com/events', + 'facebook.com/findfriends', + 'facebook.com/friends', + 'facebook.com/legal', + 'facebook.com/pg', + 'facebook.com/page', + 'facebook.com/fundraisers', + 'facebook.com/games', + 'facebook.com/groups', + 'facebook.com/help', + 'facebook.com/home.php', + 'facebook.com/intl', + 'facebook.com/jobs', + 'facebook.com/l.php', + 'facebook.com/language.php', + 'facebook.com/local_surface', + 'facebook.com/logout.php', + 'facebook.com/mbasic', + 'facebook.com/menu', + 'facebook.com/messages', + 'facebook.com/nfx', + 'facebook.com/notes', + 'facebook.com/notifications.php', + 'facebook.com/notifications', + 'facebook.com/nt', + 'facebook.com/pages', + 'facebook.com/people', + 'facebook.com/photo.php', + 'facebook.com/policies', + 'facebook.com/privacy', + 'facebook.com/reactions', + 'facebook.com/salegroups', + 'facebook.com/search', + 'facebook.com/settings', + 'facebook.com/story.php', + 'facebook.com/ufi', + 'reddit.com/r/all', + 'reddit.com/r/popular', + 'twitter.com/hashtag', + 'twitter.com/i', + 'twitter.com/search', + 'twitter.com/settings', + 'twitter.com/threadreaderapp', + 'youtube.com/watch', +].forEach(x => badIdentifiers[x] = true); + + + browser.contextMenus.onClicked.addListener(function (info, tab) { if (info.menuItemId == 'help') { openHelp(); @@ -163,6 +221,9 @@ browser.contextMenus.onClicked.addListener(function (info, tab) { debug: overrides.debug }, null, response => { if (!response.identifier) return; + if (badIdentifiers[response.identifier] && response.mark) return; + if (response.debug && /^facebook\.com\/[a-zA-Z]/.test(response.identifier)) + alert('Note: could not find numeric id for ' + response.identifier); response.tabId = tab.id; saveLabel(response); }) diff --git a/extension/content.js b/extension/content.js index 62aded6..30a4d08 100644 --- a/extension/content.js +++ b/extension/content.js @@ -406,12 +406,16 @@ function getIdentifierInternal(urlstr) { return 'facebook.com/' + (s.story_fbid || s.set || s.story_fbid || s._ft_ || s.ft_id || s.id || takeFirstPathComponents(p, p.startsWith('/groups/') ? 2 : 1).substring(1)); } if (isHostedOn(host, 'reddit.com')) { - return 'reddit.com' + takeFirstPathComponents(url.pathname.replace('/u/', '/user/'), 2).toLowerCase(); + var pathname = url.pathname.replace('/u/', '/user/'); + if (!pathname.startsWith('/user/') && !pathname.startsWith('/r/')) return null; + return 'reddit.com' + takeFirstPathComponents(pathname, 2).toLowerCase(); } if (isHostedOn(host, 'twitter.com')) { return 'twitter.com' + takeFirstPathComponents(url.pathname, 1).toLowerCase(); } if (isHostedOn(host, 'youtube.com')) { + var pathname = url.pathname; + if (!pathname.startsWith('/user/') && !pathname.startsWith('/channel/')) return null; return 'youtube.com' + takeFirstPathComponents(url.pathname, 2); } if (isHostedOn(host, 'disqus.com') && url.pathname.startsWith('/by/')) { @@ -431,7 +435,7 @@ function getIdentifierInternal(urlstr) { return null; } if (isHostedOn(host, 'wikipedia.org') || isHostedOn(host, 'rationalwiki.org')) { - if (url.hash) return null; + if (url.hash || url.pathname.includes(':')) return null; if (url.pathname.startsWith('/wiki/')) return 'wikipedia.org' + takeFirstPathComponents(url.pathname, 2); else return null; }