From 7af5eeac34e63aced87a25891ebc52eff776dfc8 Mon Sep 17 00:00:00 2001 From: John Michel Date: Sat, 4 Mar 2023 23:13:11 -0500 Subject: [PATCH] feat: Open story comments in new tab --- .../open-story-comments-in-new-tab.js | 30 +++++++++++++++++++ src/libs/initialise.js | 2 ++ 2 files changed, 32 insertions(+) create mode 100755 src/features/open-story-comments-in-new-tab.js diff --git a/src/features/open-story-comments-in-new-tab.js b/src/features/open-story-comments-in-new-tab.js new file mode 100755 index 0000000..1b71101 --- /dev/null +++ b/src/features/open-story-comments-in-new-tab.js @@ -0,0 +1,30 @@ +function init(metadata) { + const links = [ + ...(metadata.options.openCommentsInNewTab + ? document.querySelectorAll("td.subtext .subline > a:last-child") + : []), + ]; + if (links.length === 0) { + return false; + } + + for (const link of links) { + link.target = "_blank"; + link.rel = "noopener"; + } + + return true; +} + +const details = { + id: "open-story-comments-in-new-tab", + pages: { + include: ["*"], + exclude: [], + }, + loginRequired: false, + runOnJobItems: true, + init, +}; + +export default details; diff --git a/src/libs/initialise.js b/src/libs/initialise.js index acb7a5b..6ed7457 100755 --- a/src/libs/initialise.js +++ b/src/libs/initialise.js @@ -21,6 +21,7 @@ import load_more_links_in_navbar from "../features/load-more-links-in-navbar"; import more_accessible_favorite from "../features/more-accessible-favorite"; import more_accessible_flag from "../features/more-accessible-flag"; import on_link_focus_comment from "../features/on-link-focus-comment"; +import open_comment_links_in_new_tab from '../features/open-story-comments-in-new-tab'; import open_story_links_in_new_tab from "../features/open-story-links-in-new-tab"; import past_choose_date from "../features/past-choose-date"; import prefill_submit_title from "../features/prefill-submit-title"; @@ -59,6 +60,7 @@ const featureList = [ input_field_tweaks, linkify_user_about, on_link_focus_comment, + open_comment_links_in_new_tab, open_story_links_in_new_tab, backticks_to_monospace, past_choose_date,