GSeach Toggle Persian/English

GToggle can change google search language result between

当前为 2021-03-22 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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'
    })
})();