That's really just a small trick, add this code... somewhere, for example in Load.php, close to:
call_integration_hook('integrate_load_theme');
Yes, I'm just being lazy, I don't want to write the package for it. :PI created the package and uploaded as usual at github, scroll down for details.
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:
[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
Nice tip/addon. May be the favicon can be better aligned and add some space as between them.
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).
I will have a try later. It's sure a nice mod to have anyway.
Download link not working
@emanuele
https://github.com/emanuele45/Url-Favicon/releases/download/0.0.1/UrlFavicon_0-1-0.zip
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
Thank you very much
@Spuds
I'm also using it on my test forum, I like this simple addon ;)
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.
I agree it's simple but makes links look so much better.
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
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"?
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
replace
$(\'.bbc_link\').each(function() {
with
$(\'.inner .bbc_link\').each(function() {
untested!
untested!Tested and working. 8)
This works with the correct selectors (also in SMF 2,1 with our Portal system) :D
/* 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'
});
});
@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)
I saw it, let me pass February and I'll catch up with everything left around (including 1.1 beta release!). ;)
@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
PR was made, but while its pending
- use js core hostname function to eliminate the regex
- allow install w/o emulation, but this is 1.1 only (.0.0.2 did not work on 1.1, 0.0.1 did)
- update links
- Fix not adding favicon on signature links was broken on 1.1
Just installed and seems to work fine now