diff --git a/Providers/FreeHelpServiceProvider.php b/Providers/FreeHelpServiceProvider.php index aa4488f..6bf33c7 100644 --- a/Providers/FreeHelpServiceProvider.php +++ b/Providers/FreeHelpServiceProvider.php @@ -15,7 +15,29 @@ public function boot() { * Remove the "target=_blank" attribute for all links. * @see https://github.com/freescout-helpdesk/freescout/issues/2914 */ -$('[target="_blank"]').attr("target", null ); +/* $('[target="_blank"]').attr("target", null ); // i like external links to open in new window */ + +function updateExternalLinks() { + document.querySelectorAll('a[href]').forEach(function(link) { + let href = link.getAttribute('href'); + + // Ignore links that are internal, anchor (`#`), or JavaScript actions + if (href.startsWith('#') || href.startsWith('javascript:') || href.includes(location.hostname)) { + return; + } + + // Set target="_blank" and security attributes + link.setAttribute("target", "_blank"); + link.setAttribute("rel", "noopener noreferrer"); + }); +} + +// Run immediately on page load +updateExternalLinks(); + +// Run every 3 seconds in case new links are dynamically added and to account for sidebar webhooks +setInterval(updateExternalLinks, 3000); + // Let's use better terminology. $('a[href*=whitelist]').text(function ( index, text ) { diff --git a/README.md b/README.md index d24b6a7..d7e3657 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ FreeHelp makes FreeScout look and feel more like Help Scout, adding many small quality-of-life improvements. -- Don't open anything in new tabs/windows! [#2914](https://github.com/freescout-helpdesk/freescout/issues/2914) +- Open external links in new windows - Shift-click checkboxes to select a range of conversations at once [#1312](https://github.com/freescout-helpdesk/freescout/issues/1312) - Convert Dropdown-type Custom Fields to Select2 inputs - Type `Escape` to close dropdowns, cancel editing conversation titles, and cancel editing a note @@ -38,6 +38,10 @@ FreeHelp makes FreeScout look and feel more like Help Scout, adding many small q ## Changelog +### 1.0.4 - TBD + +- Open external links in new windows. Also check every few seconds for new links that may have been loaded such as from sidebar addons. + ### 1.0.3 on August 4, 2023 - Update fonts to make the editor text feel more like Help Scout's