Sidebar toggle, Ru/En lang buttons for wikipedia.org

24.05.2020, 12:45:17

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name        Sidebar toggle, Ru/En lang buttons for wikipedia.org
// @namespace   Violentmonkey Scripts
// @match       https://*.wikipedia.org/*
// @grant       none
// @version     1.1
// @author      -
// @description 24.05.2020, 12:45:17
// ==/UserScript==

const content = document.querySelector('#content')
const sidebar = document.querySelector('#mw-panel')
let open = true

const buttons = document.createElement('div')
const sidebarBtn = document.createElement('button')
const engBtn = document.createElement('button')
const rusBtn = document.createElement('button')

Object.assign(buttons.style, {position: 'absolute', top: '10px', left: '10px'})
sidebarBtn.innerText = 'sidebar'
engBtn.innerText = 'Eng'
rusBtn.innerText = 'Rus'

buttons.append(sidebarBtn, engBtn, rusBtn)

document.body.append(buttons)

function toggleSidebar() {
  if (open) {
    content.style.marginLeft = '0'
    sidebar.style.display = 'none'
  } else {
    content.style.marginLeft = null
    sidebar.style.display = null
  }
  open = !open
}

// document.body.addEventListener('keydown', e => {})

sidebarBtn.onclick = toggleSidebar

rusBtn.onclick = () => rus.click()

toggleSidebar()


const eng = document.querySelector('.interlanguage-link-target[hreflang="en"]')
const rus = document.querySelector('.interlanguage-link-target[hreflang="ru"]')

if (eng) engBtn.onclick = () => eng.click()
else engBtn.remove()
if (rus) rusBtn.onclick = () => rus.click()
else rusBtn.remove()