Open in background tab (Chrome/Opera only)

Post plugins and custom CSS snippets here
toomyzoom
Bear Rating Trainee
Bear Rating Trainee
Posts: 10
Joined: 16 Aug 2013, 13:28

Re: Open in background tab (Chrome/Opera only)

Postby toomyzoom » 20 Aug 2013, 07:37

Using the mouse event in firefox is useless (It works with Chrome and Opera though.) I can only use window.open("url") together with browser.tabs.loadDivertedInBackground set to true in about:config. Changing mouse event to something like this (same as openArticleInNewWindow(id) function)

Code: Select all

window.open("backend.php?op=article&method=redirect&id=" + id);


Because open link in background tab is not controllable by javascript but user preference, so the value browser.tabs.loadDivertedInBackground must be set to true. Replace

Code: Select all

openArticleInBackgroundTab(id);
with

Code: Select all

openArticleInNewWindow(id);
in openUnreadArticlesInBackgroundTabs() function and it will works as intended.

By the way, are you getting the idea for your openArticleInBackgroundTab(id) function by this link: http://stackoverflow.com/questions/10812628/open-a-new-tab-in-the-background? If so, seem like it only works on Chrome and Opera, where the open tab in background can be controlled by javascript.

phz
Bear Rating Disaster
Bear Rating Disaster
Posts: 77
Joined: 18 Mar 2013, 18:32

Re: Open in background tab (Chrome/Opera only)

Postby phz » 20 Aug 2013, 09:47

toomyzoom wrote:Can you make it emulate what open_in_new_window use and not mouse click event? I can't use Chrome (which is a joke) or Opera (too bloated like Chrome). Open in new window works in firefox.

The whole point of this plugin is to open things in background tabs. Firefox does not allow this, probably since so called "pop unders" used to be exploited by advertisers. Opera or Chrome does not really allow this either, but simulating a mouse click on a fictitious link is a hacky way to work around this limitation. In Firefox, however, this does not seem to work, which I would actually write down as sort of a bug in the Firefox Javascript implementation, unless it is explicitly intentional (which I can find no info regarding).

So, according to the earlier explanation and the plugin README, Firefox does not have any mechanism for this. If you look at the source you see that the hotkey action `open_in_background_tab` in the plugin does more or less exactly the same thing as the `open_in_new_window` routine (even calling the same subroutines): just diverting the tabs to background instead.

If you choose to use Firefox instead of Opera/Chrome, this plugin will not work. It's not because I don't like Firefox: it's because the functionality does not seem to exist in Firefox.

EDIT: Perhaps I misunderstood: are you talking specifically about the function to open all unread articles in one go? In that case, yeah, just change line 40 in `openArticleInBackgroundTab.js` as suggested above. This is not really central to this plugin and not really the correct place to define this function though, in my mind. The "open in background"-hack won't go into mainline since it is exactly a hack, but "Open all unread" might, if someone put it into a pull request for Fox. It would just be copy+paste-work from `openArticleInBackgroundTab.js` in this plugin, stripping out the parts dealing with "open in background" stuff.

phz
Bear Rating Disaster
Bear Rating Disaster
Posts: 77
Joined: 18 Mar 2013, 18:32

Re: Open in background tab (Chrome/Opera only)

Postby phz » 20 Aug 2013, 10:26

toomyzoom wrote:By the way, are you getting the idea for your openArticleInBackgroundTab(id) function by this link: http://stackoverflow.com/questions/10812628/open-a-new-tab-in-the-background? If so, seem like it only works on Chrome and Opera, where the open tab in background can be controlled by javascript.

Yes, it is the same technique. The source is linked in the first post in this thread and not very long; I can actually post the relevant parts right here directly from Github:

Code: Select all

// Function to simulate Ctrl+left-click. Works in Chrome/Opera, does not work
// in Firefox, not tested in other browsers.
function openArticleInBackgroundTab(id) {
  var a = document.createElement('a');
  // Target needed to work with links implementing anchors.
  a.target = '_blank';
  a.href = 'backend.php?op=article&method=redirect&id=' + id;
  var evt = document.createEvent('MouseEvents');
  // <https://developer.mozilla.org/en/docs/DOM/event.initMouseEvent>
  evt.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, true, false,
                     false, false, 0, null);
  a.dispatchEvent(evt);
}

The statement that it only works in Chrome and Opera is also quite clear by this thread title, I would say :-) . As I said above, I don't know if it's an intentional limitation or a bug in the Firefox Javascript implementation, but that the technique doesn't work in Firefox is established.

toomyzoom
Bear Rating Trainee
Bear Rating Trainee
Posts: 10
Joined: 16 Aug 2013, 13:28

Re: Open in background tab (Chrome/Opera only)

Postby toomyzoom » 20 Aug 2013, 12:52

phz wrote:The statement that it only works in Chrome and Opera is also quite clear by this thread title, I would say :-) . As I said above, I don't know if it's an intentional limitation or a bug in the Firefox Javascript implementation, but that the technique doesn't work in Firefox is established.


Yes, I understand firefox's obsessively paranoid javascript controlling scheme. I completely agree with you on that.

phz wrote:EDIT: Perhaps I misunderstood: are you talking specifically about the function to open all unread articles in one go? In that case, yeah, just change line 40 in `openArticleInBackgroundTab.js` as suggested above. This is not really central to this plugin and not really the correct place to define this function though, in my mind. The "open in background"-hack won't go into mainline since it is exactly a hack, but "Open all unread" might, if someone put it into a pull request for Fox. It would just be copy+paste-work from `openArticleInBackgroundTab.js` in this plugin, stripping out the parts dealing with "open in background" stuff.


Sorry if I was not clear on my explanation. I don't really need the open in background tab stuff because the open in new window served me just fine. The above post was like a quick hack for people who use firefox and want to use the open unread articles function from this plugin.

Thank you for writing this. I was using something similar on google reader. When I switched to TTRSS, it became a pain when I have to open about 1000 links by hand out of ~3000 articles/day.

Side question: Do you know anyway I can get the article's url with open in new window instead of this redirect "backend.php?op=article&method=redirect&id=" + id? The redirect messed up my custom load rule for my tabs based on domain.

Thank you for your work on this plugin.

phz
Bear Rating Disaster
Bear Rating Disaster
Posts: 77
Joined: 18 Mar 2013, 18:32

Re: Open in background tab (Chrome/Opera only)

Postby phz » 20 Aug 2013, 16:54

toomyzoom wrote:Side question: Do you know anyway I can get the article's url with open in new window instead of this redirect "backend.php?op=article&method=redirect&id=" + id? The redirect messed up my custom load rule for my tabs based on domain.

A database lookup is needed to find this URL, since TT-RSS presentation layer only "knows" of the article ID. The relevant function in the TT-RSS hierarchy that actually redirects to the items is the function `redirect()` in `classes/article.php`. To be able to fire directly at the final URL instead of going through this redirecting mechanism, one would need to have access to the database information with the article URLs at Javascript trigger time, which I don't think one has by default.

One could get this information into the Javascript scope via e.g. some sort of AJAX request in the article opening routine after implementing an API function to return URL from ID, or by querying the article URL for all items already on TT-RSS load, storing it in a form variable or something accessible to Javascript. Perhaps (probably) the earlier mentioned API function already exists; I have not looked into what functions are available in that area.

Another possibly easier approach for you to fix tab opening order would be to modify the internal sorting mechanism TT-RSS uses to decide presentation order. If the unread articles are sorted by feed first, then date, that would automatically group items belonging to a certain feed together, without the need of managing external rules. There are some sorting options in "Preferences" — perhaps this option is already available.

Alkarex
Bear Rating Trainee
Bear Rating Trainee
Posts: 1
Joined: 20 Aug 2013, 12:49
Contact:

Re: Open in background tab (Chrome/Opera only)

Postby Alkarex » 20 Aug 2013, 22:53

Hello,
FYI, I have posted a pull request with a simple patch to allow the default behaviour of the browser during control+click (e.g. open in background tab):

https://github.com/gothfox/Tiny-Tiny-RSS/pull/284

It should work on all browsers, including Firefox, Internet Explorer, Opera, and Chrome.

phz
Bear Rating Disaster
Bear Rating Disaster
Posts: 77
Joined: 18 Mar 2013, 18:32

Re: Open in background tab (Chrome/Opera only)

Postby phz » 21 Aug 2013, 12:59

Alkarex wrote:Hello,
FYI, I have posted a pull request with a simple patch to allow the default behaviour of the browser during control+click (e.g. open in background tab):

https://github.com/gothfox/Tiny-Tiny-RSS/pull/284

It should work on all browsers, including Firefox, Internet Explorer, Opera, and Chrome.

Ctrl+click and middle-click on a TT-RSS item title to open in background tab actually already works here in both Opera and Chrome (on Linux). Middle-click works in Firefox as well, but not Ctrl+click (which opens in foreground). I run a somewhat recent TT-RSS Git snapshot, but I don't remember having had any issue with it in earlier versions either, so it's probably a Firefox-only issue.

I don't think it will affect this plugin, suddenly making it work in Firefox, since this minimal test of the plugin mechanism, independent of the TT-RSS presentation layer, fails in Firefox.

User avatar
dxbi
Bear Rating Disaster
Bear Rating Disaster
Posts: 62
Joined: 16 Mar 2013, 13:44

Re: Open in background tab (Chrome/Opera only)

Postby dxbi » 21 Aug 2013, 13:51

Ctrl-Click on a link inside an article will open the article (not the link target) in a background tab for me (Chromium/Linux).

phz
Bear Rating Disaster
Bear Rating Disaster
Posts: 77
Joined: 18 Mar 2013, 18:32

Re: Open in background tab (Chrome/Opera only)

Postby phz » 21 Aug 2013, 17:59

dxbi wrote:Ctrl-Click on a link inside an article will open the article (not the link target) in a background tab for me (Chromium/Linux).

OK, thanks for the clarification, I only wrote about the item title links. I can confim that Ctrl+click on a link opens the article and not the link target here as well, but middle-click on the links works as intended. I've never noticed since a) I guess I almost exclusively open the articles and not links therein directly from TT-RSS and b) I always use middle-click and not Ctrl+click to open links in background tabs.

With that settled, it mostly leaves me perplexed as to why the issue was raised in this thread at all, since this plugin does not have anything to do with that :-) . The plugin opens only articles by design, and only concerns keyboard operation via hotkeys.

phz
Bear Rating Disaster
Bear Rating Disaster
Posts: 77
Joined: 18 Mar 2013, 18:32

Re: Open in background tab (Chrome/Opera only)

Postby phz » 01 Dec 2014, 19:21

Note the compatibility update regarding Google Chrome in the first post in this thread (and on Github):
phz wrote:It stopped working in the Google Chrome development channel somewhere around version 41.0.2224.3, released late 2014. The stable and beta channel will probably follow in closing this functionality, since it can be considered somewhat of a bug to begin with.

The functionality can be tested with this JSFiddle. If the Google tab opens in a background tab, it works in the current browser. If it opens in the foreground, it does not.

This was a hack to begin with (since it could be abused to create pop-unders), so it is not surprising that it would sooner or later disappear. Perhaps someone will dig up another more reliable method to accomplish the same task.

ArchCarrier
Bear Rating Trainee
Bear Rating Trainee
Posts: 16
Joined: 04 Apr 2013, 20:35

Re: Open in background tab (Chrome/Opera only)

Postby ArchCarrier » 15 Dec 2014, 23:22

The plugin hadn't been working for a few weeks now, but since today it works again. I'm on Chrome build 40.0.2214.38 beta-m. Hopefully it stays this way!


Return to “Themes and plugins”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest