GSeach Toggle Persian/English

GToggle can change google search language result between

Od 22.03.2021.. Pogledajte najnovija verzija.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         GSeach Toggle Persian/English
// @name:fa      سوییچ فارسی/انگلیسی گوگل
// @homepage     https://github.com/Soheyl
// @author       Soheyl
// @version      0.1
// @description  GToggle can change google search language result between 
//               English and Persian without any effect in RTL direction. (fork as tgxhx)
// @description:fa با این اسکریپت به راحتی می‌توان بین زبان انگلیسی و فارسی
//               در جستجوی گوگل سوییچ کرد، البته بدون تغییر در چینش
//               صفحه از چپ به راست.
// @namespace    M.Khani
// @match        https://www.google.com/search*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const settingsBtn = document.querySelector('#abar_button_opt');
    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'
    })
})();