ElkArte Community

Extending Elk => Addons => Topic started by: emanuele on May 12, 2014, 06:17:14 am

Title: [ADDON/TRICK] favicon next to links
Post by: emanuele on May 12, 2014, 06:17:14 am
That's really just a small trick, add this code... somewhere, for example in Load.php, close to:
Code: [Select]
call_integration_hook('integrate_load_theme');
Yes, I'm just being lazy, I don't want to write the package for it. :P
I created the package and uploaded as usual at github, scroll down for details.

Code: [Select]
	addInlineJavascript('
$(document).ready(function() {
$(\'.bbc_link\').each(function() {
var url = $(this).attr(\'href\'),
domain = url.match(/:\/\/(.[^/]+)/)[1],
schema = url.match(/^(http[s]*):\/\//)[1];
$(this).css({
\'background-image\': \'url(//www.google.com/s2/favicons?domain=\' + schema + \'://\' + domain + \')\',
\'background-repeat\': \'no-repeat\',
\'padding-left\': \'20px\'
});
});
})', true);

This will show the favicon of the site you linked in posts.
So, using for example:
Code: [Select]
[url=http://www.elkarte.net/community/index.php]ElkArte[/url]
It will show:
(https://www.google.com/s2/favicons?domain=http://www.elkarte.net)ElkArte (http://www.elkarte.net/community/index.php)

License
o This ElkArte Addon is subject to the terms of the BSD "3-clause" license. You can obtain a copy of the License at http://opensource.org/licenses/BSD-3-Clause

Repository / Download



Change log

  • 0.0.1 - Initial release
Title: Re: [ADDON/TRICK] favicon next to links
Post by: ahrasis on October 07, 2014, 08:13:41 am
Nice tip/addon. May be the favicon can be better aligned and add some space as between them.
Title: Re: [ADDON/TRICK] favicon next to links
Post by: emanuele on October 08, 2014, 11:37:18 am
Do not trust what you see above in the "It will show:" in terms of spacing alignment, this is standard bbcode, while the way the addon appears is different (I was too lazy to take a real screenshot LOL).
Title: Re: [ADDON/TRICK] favicon next to links
Post by: ahrasis on October 08, 2014, 11:46:56 am
I will have a try later. It's sure a nice mod to have anyway.
Title: Re: [ADDON/TRICK] favicon next to links
Post by: Allan on December 13, 2014, 08:04:33 pm
Download link not working @emanuele
Title: Re: [ADDON/TRICK] favicon next to links
Post by: Spuds on December 13, 2014, 10:19:00 pm
https://github.com/emanuele45/Url-Favicon/releases/download/0.0.1/UrlFavicon_0-1-0.zip
Title: Re: [ADDON/TRICK] favicon next to links
Post by: ahrasis on December 14, 2014, 12:39:04 am
Can we use YQL instead? How to translate this code (using http://bbc.co.uk/ as domain):

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D"http://bbc.co.uk/"and%20xpath%3D"/html/head/link[@rel%3D'icon']%20|%20/html/head/link[@rel%3D'ICON']%20|%20/html/head/link[@rel%3D'shortcut%20icon']%20|%20/html/head/link[@rel%3D'SHORTCUT%20ICON']"&format=json&callback=grab
Title: Re: [ADDON/TRICK] favicon next to links
Post by: Allan on December 14, 2014, 07:28:50 am
Thank you very much @Spuds
Title: Re: [ADDON/TRICK] favicon next to links
Post by: radu81 on December 14, 2014, 07:38:03 am
I'm also using it on my test forum, I like this simple addon ;)
Title: Re: [ADDON/TRICK] favicon next to links
Post by: emanuele on December 14, 2014, 08:08:58 am
Quote from: ahrasis – Can we use YQL instead? How to translate this code (using http://bbc.co.uk/ as domain):

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D"http://bbc.co.uk/"and%20xpath%3D"/html/head/link[@rel%3D'icon']%20|%20/html/head/link[@rel%3D'ICON']%20|%20/html/head/link[@rel%3D'shortcut%20icon']%20|%20/html/head/link[@rel%3D'SHORTCUT%20ICON']"&format=json&callback=grab

I guess its possible. But it may require some more "tricks".
I suspect you are referring to:
http://stackoverflow.com/questions/2057636/get-websites-favicon-with-js
These urls return either a json object (in case as argument of a function) or an xml file. So, instead of apply the google url to the background property, it means: do the "query", grab the favicon from the result, and set it.
Title: Re: [ADDON/TRICK] favicon next to links
Post by: Allan on December 14, 2014, 08:09:59 am
I agree it's simple but makes links look so much better.
Title: Re: [ADDON/TRICK] favicon next to links
Post by: radu81 on February 09, 2016, 02:51:38 pm
Is there a way to disable this addon into signatures? I have no links enabled into sigs but with this addon the links are visible into signature
Title: Re: [ADDON/TRICK] favicon next to links
Post by: emanuele on February 09, 2016, 04:16:11 pm
That's unlikely, this addon just adds a bit of javascript, if something is not there it cannot be shown... :-\
Van you point me to a page where I can see it "in action"?
Title: Re: [ADDON/TRICK] favicon next to links
Post by: radu81 on February 10, 2016, 06:06:15 pm
I should first try on a clean install to see if a member can add links into signature if the url and iurl codes are disabled for signatures. you can see it here skodaclub.it/index.php?topic=5802
the author of the post has a link into his signature. It's not a big problem for me, I can live with this, but I was just curious to know if this is caused by the addon
Title: Re: [ADDON/TRICK] favicon next to links
Post by: live627 on February 14, 2016, 04:26:03 pm
Quote from: radu81 – Is there a way to disable this addon into signatures? I have no links enabled into sigs but with this addon the links are visible into signature
replace

Code: [Select]
		$(\'.bbc_link\').each(function() {

with

Code: [Select]
		$(\'.inner .bbc_link\').each(function() {

untested!
Title: Re: [ADDON/TRICK] favicon next to links
Post by: Burke Knight on February 14, 2016, 04:31:52 pm


untested!

Tested and working.  8)
Title: Re: [ADDON/TRICK] favicon next to links
Post by: Feline on February 21, 2016, 11:31:38 am
This works with the correct selectors (also in SMF 2,1 with our Portal system)  :D
Code: [Select]
 /* add Favicon to links with the class "bbc_link", but not in signatures! */
 $(':not(.signature)>.bbc_link').each(function() {
 var url = $(this).attr('href'),
 domain = url.match(/:\/\/(.[^/]+)/)[1],
 schema = url.match(/^(http[s]*):\/\//)[1];
 $(this).css({
 'background-image':'url(//www.google.com/s2/favicons?domain=' + schema + '://' + domain + ')',
 'background-repeat':'no-repeat',
 'padding-left':'20px',
 'background-position':'0'
 });
 });
Title: Re: [ADDON/TRICK] favicon next to links
Post by: Burke Knight on February 22, 2016, 07:21:47 pm
@emanuele,
I have forked and done an update to this, with the not-in signatures fix, (Per http://www.elkarte.net/community/index.php?topic=1419.msg23396#msg23396 ) and sent a PR to your master, if want it.
If would like to keep both versions, let me know, and I'll make it another Branch and then send new PR, so you can have both Branches. (Also added a ReadMe....XD)
Title: Re: [ADDON/TRICK] favicon next to links
Post by: emanuele on February 23, 2016, 05:37:28 am
I saw it, let me pass February and I'll catch up with everything left around (including 1.1 beta release!). ;)
Title: Re: [ADDON/TRICK] favicon next to links
Post by: radu81 on September 16, 2017, 07:40:32 pm
@emanuele‍ don't forget about 1.1 release, the actual version installs without errors on 1.1 RC2, but no icon is shown near to links
Title: Re: [ADDON/TRICK] favicon next to links
Post by: Spuds on November 06, 2022, 01:15:06 pm
PR was made, but while its pending

Title: Re: [ADDON/TRICK] favicon next to links
Post by: radu81 on November 06, 2022, 01:23:08 pm
Just installed and seems to work fine now