GSeach Toggle Persian/English

GToggle can change google search language result between

目前為 2021-03-22 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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'
    })
})();