Last active
April 22, 2023 03:30
-
-
Save Amm1rr/218d38aa0bedae2d8955aae49199006e to your computer and use it in GitHub Desktop.
An userscript that can switch google search result between Persian and English
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
// ==UserScript== | |
// @name GSeach Toggle Persian/English | |
// @name:fa سوییچ فارسی/انگلیسی گوگل | |
// @version 0.3 | |
// @author Amir | |
// @description GToggle can change google search language result between | |
// English and Persian without any effect in RTL direction. (fork as tgxhx) | |
// @description:fa با این اسکریپت به راحتی میتوان بین زبان انگلیسی و فارسی | |
// در جستجوی گوگل سوییچ کرد، البته بدون تغییر در چینش | |
// صفحه از چپ به راست. | |
// @homepage https://github.com/Amm1rr | |
// @namespace M.Khani | |
// @match https://www.google.com/search* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
//const settingsBtn = document.querySelector('#abar_button_opt'); | |
const settingsBtn = document.querySelector('#hdtb-tls'); | |
const settingsBtnParent = settingsBtn.parentElement; | |
const a = document.createElement('a'); | |
const query = new URLSearchParams(decodeURIComponent(location.search)); | |
const isFarsi = (query.get('lr') || '').toLowerCase() === 'lang_fa'; | |
if (isFarsi) { | |
query.delete('lr'); | |
query.delete('tbs'); | |
a.textContent = 'English'; | |
} else { | |
query.set('lr', 'lang_fa'); | |
query.set('tbs', 'lr:lang_1fa'); | |
a.textContent = 'Persian'; | |
} | |
const href = `${location.origin}${location.pathname}?${query.toString()}`; | |
a.setAttribute('href', href); | |
a.classList.add('hdtb-tl'); | |
a.style.cssText = 'color: #5f6368;text-decoration: none;' | |
settingsBtnParent.insertBefore(a, settingsBtn) | |
Object.assign(settingsBtnParent.style, { | |
height: '100%', | |
display: 'flex', | |
'align-items': 'baseline' | |
}) | |
Object.assign(settingsBtnParent.parentElement.style, { | |
flex: 1, | |
display: 'flex', | |
'justify-content': 'flex-end', | |
'align-items': 'baseline' | |
}) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment