Open in background tab (Chrome/Opera only)

Post plugins and custom CSS snippets here
phz
Bear Rating Disaster
Bear Rating Disaster
Posts: 77
Joined: 18 Mar 2013, 18:32

Open in background tab (Chrome/Opera only)

Postby phz » 02 Apr 2013, 19:15

OpenInBgTab
This Tiny Tiny RSS plugin will register a new action that opens links in a background tab by using a JS "hack", simulating a Ctrl-click on a fictive link element. This currently works in Chrome and Opera, does not work in Firefox and is not tested in anything else. Update: 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. End update.

Since this is the first plugin that uses the `HOOK_HOTKEY_INFO` hook, I've commented everything rigorously in case anyone wants a sample implementation of this functionality.

Some additional functionality was added that registers another action with corresponding hotkey that opens all unread articles in the current view in background tabs and marks them as read. In Chrome, this requires explicit permission to be given for the TT-RSS instance domain to open pop-ups whenever multiple tabs are to be opened. Until this permission is given, Chrome will hide the tabs under a "Blocked pop-up windows" icon in the address bar. Chrome will prompt regarding this when the hotkey is triggered and tries to open multiple tabs.

Requirements
TT-RSS ≥1.7.6.

For TT-RSS ≤1.7.8, use v1.1 of this plugin since the TT-RSS plugin API changed slightly at that point (a single line in the plugin was removed and a backwards compatible `api_version()` function for future API version checks were added; would be easy to manually "backport" for that matter).

Upstream
The project lives at https://github.com/dandersson/ttrss-openinbgtab.

Updated description at 2013–06–11. The README at Github should always hold the latest information.
Updated description at 2014–12–01 regarding compatibility; specifically the part about the Google Chrome development version.
Last edited by phz on 01 Dec 2014, 19:13, edited 3 times in total.

User avatar
fox
^ me reading your posts ^
Posts: 6318
Joined: 27 Aug 2005, 22:53
Location: Saint-Petersburg, Russia
Contact:

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

Postby fox » 02 Apr 2013, 19:29

Adding to the wiki.

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 » 02 Apr 2013, 19:41

fox wrote:Adding to the wiki.

Aww, I was currently wording out my request for this in the request thread :-) .

User avatar
fox
^ me reading your posts ^
Posts: 6318
Joined: 27 Aug 2005, 22:53
Location: Saint-Petersburg, Russia
Contact:

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

Postby fox » 02 Apr 2013, 19:43

It would be nice to have a centralized plugin server with automatic updates using update.php...

User avatar
idoxlr8
Bear Rating Trainee
Bear Rating Trainee
Posts: 46
Joined: 25 Mar 2013, 20:04
Location: Texas, USA
Contact:

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

Postby idoxlr8 » 02 Apr 2013, 20:47

Great stuff there, I like that you have taken the time to comment. This helps the learning process.
I have been messing around on a chrome only plugin and i used the snippet below to grab the HTTP_USER_AGENT,
that way the plugin does not even load if it's not the right browser...

Code: Select all

if (strpos($_SERVER['HTTP_USER_AGENT'], "Chrome") !== false) {

do some stuff here...
}

Just my 2 cents...

onyxfox
Bear Rating Trainee
Bear Rating Trainee
Posts: 18
Joined: 19 Mar 2013, 11:54

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

Postby onyxfox » 02 Apr 2013, 21:30

I'll have to give this plugin a try. I had added an open in background tab js call to the context menu's Open Original Article entry on my install, but using this plugin might be less hassle to maintain.

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 » 02 Apr 2013, 21:45

idoxlr8 wrote:I have been messing around on a chrome only plugin and i used the snippet below to grab the HTTP_USER_AGENT,
that way the plugin does not even load if it's not the right browser...

Code: Select all

if (strpos($_SERVER['HTTP_USER_AGENT'], "Chrome") !== false) {

do some stuff here...
}

Just my 2 cents...

I'll certainly look at such solutions if I find a different method for it to work on e.g. Firefox, so I can use a single plugin with behavior dependent on the user agent. At the moment though, the only thing that happens on non-supported browsers if the hotkey is triggered is… nothing :-), so I'll let it be in its current state.

yelfathi
Bear Rating Trainee
Bear Rating Trainee
Posts: 20
Joined: 14 May 2013, 19:32

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

Postby yelfathi » 14 May 2013, 19:42

Hello, it does not work for me, I am using the latest version of TT-RSS and stable chrome version. Thanks

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 » 15 May 2013, 16:14

yelfathi wrote:Hello, it does not work for me, I am using the latest version of TT-RSS and stable chrome version. Thanks

Some counter-questions relevant to finding out why:
  1. When you say "latest version of TT-RSS", do you mean trunk from Git or latest versioned release, and in that case: which version? Is it perhaps via third-party distribution such as Debian?
  2. Have you managed to get other plugins to work?
  3. Have you managed to get other user-contributed plugins to work (i.e. those you need to install yourself)?
  4. Has the plugin worked for you before?
  5. Do you use the latest version of the plugin?
  6. What exactly does not work? Does it
    1. not show up among plugins?
    2. not do anything when the keyboard shortcut (Shift+o by default; check "Actions"→"Keyboard shortcuts help" to make sure it's shown there) is triggered?
    3. open a link but not in the background?
I've been using trunk continuously since the plugin was written and have had no problems, so without being able to reproduce any errors, there is not much I can do. I'm using Google Chrome Unstable on this machine (Debian), but Stable on another (Ubuntu).

You could try to launch the Javascript console to see if there are any suspicious messages thrown out when you activate the shortcut, but start with the points above.

yelfathi
Bear Rating Trainee
Bear Rating Trainee
Posts: 20
Joined: 14 May 2013, 19:32

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

Postby yelfathi » 15 May 2013, 16:29

Thanks for your help, the answers are in bold!

phz wrote:
yelfathi wrote:Hello, it does not work for me, I am using the latest version of TT-RSS and stable chrome version. Thanks

Some counter-questions relevant to finding out why:
  1. When you say "latest version of TT-RSS", do you mean trunk from Git or latest versioned release, and in that case: which version? Is it perhaps via third-party distribution such as Debian?
    1.7.9 downloaded from the tt-rss.org website, it is hosted on a provider
  2. Have you managed to get other plugins to work?
  3. Have you managed to get other user-contributed plugins to work (i.e. those you need to install yourself)?
    Yes like article_headline_toggle, embed_original, share with pocket/twitter/g+, markbutton
  4. Has the plugin worked for you before?
    Nope I was using version 1.7.8
  5. Do you use the latest version of the plugin?
    Yes but I modified line 10 of the php file, replaced the [] by array (), without this mod the plugin tab won't show in preferences
  6. What exactly does not work? Does it
    1. not show up among plugins?
      It shows
    2. not do anything when the keyboard shortcut (Shift+o by default; check "Actions"→"Keyboard shortcuts help" to make sure it's shown there) is triggered?
      The shortcut shift+o works
    3. open a link but not in the background?
      Exactly

I've been using trunk continuously since the plugin was written and have had no problems, so without being able to reproduce any errors, there is not much I can do. I'm using Google Chrome Unstable on this machine (Debian), but Stable on another (Ubuntu).

You could try to launch the Javascript console to see if there are any suspicious messages thrown out when you activate the shortcut, but start with the points above.

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 » 15 May 2013, 20:23

yelfathi wrote:
  • Do you use the latest version of the plugin?
Yes but I modified line 10 of the php file, replaced the [] by array (), without this mod the plugin tab won't show in preferences

OK, the short syntax for arrays was added in PHP 5.4, so you probably have an older PHP version installed. TT-RSS is supposed to support PHP 5.3 if I recall correctly, so I'll change that at GitHub sometime; it's only function is to keep the code tidier. What's surprising to me is that TT-RSS did not choke entirely on invalid syntax in the plugin file, but that's probably also explainable somehow.

yelfathi wrote:
  • open a link but not in the background?
    Exactly

The plugin creates a new hidden link and simulates a Ctrl+left-click action on that — does manually performing Ctrl+left-click on any other link open it in a background tab in your browser? I guess this is configurable behavior somewhere (but the default one should be the one used in the plugin).

You could try changing line 18+19 in openArticleInBackgroundTab.js to:

Code: Select all

  evt.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false,
                     false, false, 1, null);

That should simulate a middle-click instead, which performs the same action in Chrome. Perhaps you have some setting/application that interferes with Ctrl+left-click for some reason.

I remembered something else just now: I've read that on Mac OS X (I should probably add "Which OS?" to the previous error searching form :-) ), it might be necessary to also hold the "Meta" key to open in background tab. If that applies, try:

Code: Select all

  evt.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, true, false,
                     false, true, 0, null);

The syntax of evt.initMouseEvent is explained at MDN.

yelfathi
Bear Rating Trainee
Bear Rating Trainee
Posts: 20
Joined: 14 May 2013, 19:32

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

Postby yelfathi » 15 May 2013, 21:19

My provider has only PhP 5.3 and I am using Win7 and Ctrl+Left click works well.

I modified line 18+19 of openArticleInBackgroundTab.js but same problem :(

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 » 16 May 2013, 12:45

yelfathi wrote:My provider has only PhP 5.3 and I am using Win7 and Ctrl+Left click works well.

I modified line 18+19 of openArticleInBackgroundTab.js but same problem :(

OK, well, I don't have Windows machines to test on specifically, but if Ctrl+left-click works it shouldn't be OS specific. As long as the plugin loads OK (i.e. shows in "Keyboard shortcuts help" and adds its Javascript to the inline <script> tag in the index header), then it should be using the exact same mechanism that TT-RSS itself uses to open links; just with the "hidden element" quirk.

First: try this implementation: http://jsfiddle.net/3ZmvS/5/ . If that doesn't work, then we can rule out TT-RSS part of the equation and pin-point the issue to browser behavior.

I tried with an older Chrome version (specifically Chromium 25.0.1364.160) with vanilla settings and it worked without a problem.

To check that the Javascript is correctly inserted: view source on the TT-RSS page and search for the function name "openArticleInBackgroundTab". It should be among the last of the inline Javascript in the header. If this is not the case, it might be a problem with your hosting, but if this kind if inclusion doesn't work, TT-RSS itself should probably have crashed and burned. Could be that the permissions on the plugin files have gotten borked so that the web server can't read the Javascript file, or something (but then the hotkey handling shouldn't really work anyway to open the tab in the foreground).

Perhaps there is some Chrome plugin disturbing the behavior; some anti-ad plugin that blocks "clever" tricks like this. I'm running Chrome with Adblock Plus myself, though, and there is no issue with that.

If you see this image:
Image
in the address bar of Chrome, then Chrome has blocked the window as a "pop-up window". You can click on this icon to permanently allow "pop-ups" from the host in question. I would actually say it is a bug that Chrome and others does not block the simulated click as a pop-up window, but what can I do :-) .

Try opening the Javascript console in Chrome (Ctrl+Shift+J), select a TT-RSS article and run this in the console:

Code: Select all

openArticleInBackgroundTab(getActiveArticleId())

On my installation, this will trigger Chrome's internal "Pop-ups where blocked on this page" icon mentioned above. If this is the case for you as well: then the problem is in the hotkey handling and not the function. If this opens the window in the front instead of in a background tab: I can only assume that the problem is some profile specific setting on your end. There is a section regarding pop-ups in Chrome settings at "Settings"→"Advanced settings"→"Privacy"→"Content settings"→"Pop-ups", but on the installations I run, this is set to "Do not allow any site to show pop-ups (recommended)" without exceptions and it works fine.

Without being able to reproduce there is not much more I can do. It seems to work for others, and it's not a very big plugin code-wise, so there are not many places where things could go wrong — especially not if it has loaded correctly.

yelfathi
Bear Rating Trainee
Bear Rating Trainee
Posts: 20
Joined: 14 May 2013, 19:32

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

Postby yelfathi » 16 May 2013, 14:18

Thanks again for helping me:
- http://jsfiddle.net/3ZmvS/5/ works for me when I click on the button it opens it in background
- In the TT-RSS source page I see the function name openArticleInBackgroundTab:

Code: Select all

new Ajax.Request("backend.php",{parameters:query,onComplete:function(transport){var ti=JSON.parse(transport.responseText);if(ti){var iframe=new Element("iframe",{class:"embeddedContent",src:ti.url,width:(c.parentNode.offsetWidth-5)+'px',height:(c.parentNode.parentNode.offsetHeight-c.parentNode.firstChild.offsetHeight-5)+'px',style:"overflow: auto; border: none; min-height: "+(document.body.clientHeight/2)+"px;",sandbox:'allow-scripts',});if(c){Element.hide(c);c.parentNode.insertBefore(iframe,c);if(isCdmMode()){cdmScrollToArticleId(id,true);}}}}});}catch(e){exception_error("embedOriginalArticle",e);}} function shareArticleToGooglePlus(id){try{var query="?op=pluginhandler&plugin=googleplus&method=getInfo&id="+param_escape(id);console.log(query);var d=new Date();var ts=d.getTime();var w=window.open('backend.php?op=backend&method=loading','ttrss_tweet',"status=0,toolbar=0,location=0,width=500,height=450,scrollbars=1,menubar=0");new Ajax.Request("backend.php",{parameters:query,onComplete:function(transport){var ti=JSON.parse(transport.responseText);var share_url="https://plus.google.com/share?url="+param_escape(ti.link);w.location.href=share_url;}});}catch(e){exception_error("tweetArticle",e);}}
hotkey_actions['open_in_background_tab']=function(){if(getActiveArticleId()){openArticleInBackgroundTab(getActiveArticleId());return;}};function openArticleInBackgroundTab(id){var a=document.createElement('a');a.target='_blank';a.href='backend.php?op=article&method=redirect&id='+id;var evt=document.createEvent('MouseEvents');evt.initMouseEvent('click',true,true,window,0,0,0,0,0,true,false,false,false,0,null);a.dispatchEvent(evt);} function shareArticleToPocket(id){try{var query="?op=pluginhandler&plugin=pocket&method=getInfo&id="+param_escape(id);console.log(query);var d=new Date();var ts=d.getTime();var w=window.open('backend.php?op=backend&method=loading','ttrss_tweet',"status=0,toolbar=0,location=0,width=500,height=400,scrollbars=1,menubar=0");new Ajax.Request("backend.php",{parameters:query,onComplete:function(transport){var ti=JSON.parse(transport.responseText);var share_url="https://getpocket.com/save?"+"&title="+param_escape(ti.title)+"&url="+param_escape(ti.link.strip());w.location.href=share_url;}});}catch(e){exception_error("tweetArticle",e);}} function tweetArticle(id){try{var query="?op=pluginhandler&plugin=tweet&method=getInfo&id="+param_escape(id);console.log(query);var d=new Date();var ts=d.getTime();var w=window.open('backend.php?op=backend&method=loading','ttrss_tweet',"status=0,toolbar=0,location=0,width=500,height=400,scrollbars=1,menubar=0");new Ajax.Request("backend.php",{parameters:query,onComplete:function(transport){var ti=JSON.parse(transport.responseText);var share_url="http://twitter.com/share?_="+ts+"&text="+param_escape(ti.title)+"&url="+param_escape(ti.link);w.location.href=share_url;}});}catch(e){exception_error("tweetArticle",e);}}var T_messages = new Object();

- I disabled the popup-blocker extension and still the problem
- I tried openArticleInBackgroundTab(getActiveArticleId()) and it works fine
- I tried with Opera and different Chrome versions: same problem

It is very weird!

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 » 16 May 2013, 16:03

yelfathi wrote:- I tried openArticleInBackgroundTab(getActiveArticleId()) and it works fine

Alright, then it must be something with the general hotkey handling that doesn't work on your installation.

If you look in "Actions…"→"Keyboard shortcuts help", you should have the entries:

Code: Select all

o         Open in new window
Shift+o   Open in background tab (Chrome/Opera only)

Try changing the hotkey for "Open in background tab" to some other unused character by editing `init.php` and reloading; specifically something without the Shift modifier (also try to see if any of the hotkeys with Shift modifier works). That is, change the array index in line 41 in `init.php` to e.g.:

Code: Select all

        $hotkeys['y'] = 'open_in_background_tab';

and reload. Check that "Actions…"→"Keyboard shortcuts help" now says:

Code: Select all

o         Open in new window
y         Open in background tab (Chrome/Opera only)

and try the new hotkey. Perhaps you have other shortcuts defined that are shadowing Shift+o, or perhaps it is a general internationalization issue with the way TT-RSS handles Shift key modifiers (some tricky unexpected key code issue).


Return to “Themes and plugins”

Who is online

Users browsing this forum: No registered users and 3 guests