Last active
August 29, 2015 14:05
-
-
Save rossmari/080aad9e28967c73f181 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//before code to detect browser and change some link | |
var user_agent = navigator.userAgent; | |
function userAgentCheck(r) { | |
return r.test(user_agent); | |
} | |
function changeBrowserExtensionLink() { | |
if (userAgentCheck(/OPR/)) { | |
replaceBrowserExtLnk('Opera', 'opera', 'https://addons.opera.com/ru/extensions/details/novosti-i-pogoda-krasnoiarska-sibnovostiru/'); | |
} else if (userAgentCheck(/Firefox/)) { | |
// replaceBrowserExtLnk('Firefox', 'firefox', ''); | |
replaceBrowserExtLnk('Google Chrome', 'chrome', 'https://chrome.google.com/webstore/detail/%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B8-%D0%B8-%D0%BF%D0%BE%D0%B3%D0%BE%D0%B4%D0%B0-%D0%BA%D1%80%D0%B0%D1%81%D0%BD%D0%BE%D1%8F%D1%80/pkpejndjbgkfnkfmiehkpbbholhakjno?hl=ru&utm_source=chrome-ntp-launcher'); | |
} else if (userAgentCheck(/YaBrowser/)) { | |
replaceBrowserExtLnk('Yandex Browser', 'chrome', 'https://chrome.google.com/webstore/detail/%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B8-%D0%B8-%D0%BF%D0%BE%D0%B3%D0%BE%D0%B4%D0%B0-%D0%BA%D1%80%D0%B0%D1%81%D0%BD%D0%BE%D1%8F%D1%80/pkpejndjbgkfnkfmiehkpbbholhakjno?hl=ru&utm_source=chrome-ntp-launcher'); | |
} else if (userAgentCheck(/Safari/) && userAgentCheck(/Version/)) { | |
// replaceBrowserExtLnk('Safari', 'safari', ''); | |
replaceBrowserExtLnk('Google Chrome', 'chrome', 'https://chrome.google.com/webstore/detail/%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B8-%D0%B8-%D0%BF%D0%BE%D0%B3%D0%BE%D0%B4%D0%B0-%D0%BA%D1%80%D0%B0%D1%81%D0%BD%D0%BE%D1%8F%D1%80/pkpejndjbgkfnkfmiehkpbbholhakjno?hl=ru&utm_source=chrome-ntp-launcher'); | |
} else if (userAgentCheck(/Chrome/)) { | |
replaceBrowserExtLnk('Google Chrome', 'chrome', 'https://chrome.google.com/webstore/detail/%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B8-%D0%B8-%D0%BF%D0%BE%D0%B3%D0%BE%D0%B4%D0%B0-%D0%BA%D1%80%D0%B0%D1%81%D0%BD%D0%BE%D1%8F%D1%80/pkpejndjbgkfnkfmiehkpbbholhakjno?hl=ru&utm_source=chrome-ntp-launcher'); | |
} | |
} | |
function replaceBrowserExtLnk(browser_name, browser_id, link){ | |
var lnk = $('.link_socicons.browser_ext'); | |
lnk.attr('title', 'Расширение для Sibnovosti для ' + browser_name); | |
lnk.attr('href', link); | |
var img = lnk.find('img'); | |
img.attr('alt', 'Sibnovosti.ru для ' + browser_name); | |
img.attr('src', '/images/social_and_browser_icons/' + browser_id + '.png') | |
} | |
$(document).ready(function(){ | |
changeBrowserExtensionLink(); | |
}); | |
//after code - to detect browser and change link with received params | |
var user_agent = navigator.userAgent; | |
function userAgentCheck(r) { | |
return r.test(user_agent); | |
} | |
function getBrowserName() | |
{ | |
if (userAgentCheck(/OPR/)) | |
{ | |
return 'opera'; | |
} | |
else if (userAgentCheck(/Firefox/)) | |
{ | |
return 'chrome'; | |
} | |
else if (userAgentCheck(/YaBrowser/)) | |
{ | |
return 'yandex'; | |
} | |
else if (userAgentCheck(/Safari/) && userAgentCheck(/Version/)) | |
{ | |
return 'chrome'; | |
} | |
else if (userAgentCheck(/Chrome/)) | |
{ | |
return 'chrome'; | |
} | |
} | |
function link_browser_replacer(params) | |
{ | |
var browsers = {opera: {browser_name: 'Opera', browser_id: 'opera', link: 'https://addons.opera.com/ru/extensions/details/novosti-i-pogoda-krasnoiarska-sibnovostiru/'}, | |
chrome: {browser_name: 'Google Chrome', browser_id: 'chrome', link: 'https://chrome.google.com/webstore/detail/%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B8-%D0%B8-%D0%BF%D0%BE%D0%B3%D0%BE%D0%B4%D0%B0-%D0%BA%D1%80%D0%B0%D1%81%D0%BD%D0%BE%D1%8F%D1%80/pkpejndjbgkfnkfmiehkpbbholhakjno?hl=ru&utm_source=chrome-ntp-launcher'}, | |
yandex: {browser_name: 'Yandex Browser', browser_id: 'chrome', link: 'https://chrome.google.com/webstore/detail/%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B8-%D0%B8-%D0%BF%D0%BE%D0%B3%D0%BE%D0%B4%D0%B0-%D0%BA%D1%80%D0%B0%D1%81%D0%BD%D0%BE%D1%8F%D1%80/pkpejndjbgkfnkfmiehkpbbholhakjno?hl=ru&utm_source=chrome-ntp-launcher'}} | |
var browser_hash = browsers[getBrowserName()]; | |
var browser_name = browser_hash['browser_name']; | |
var lnk = $(params['selector']); | |
lnk.attr('title', params['title'] + browser_name); | |
lnk.attr('href', browser_hash['link'] ); | |
var img = lnk.find('img'); | |
img.attr('alt', 'Sibnovosti.ru для ' + browser_name); | |
img.attr('src', '/images/social_and_browser_icons/' + browser_hash['browser_id'] + '.png') | |
} | |
//using of new code | |
var main_page_params = { selector: '.link_socicons.browser_ext', title: 'Расширение для Sibnovosti для '}; | |
link_browser_replacer(main_page_params); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment