Skip to content

Instantly share code, notes, and snippets.

@kossnocorp
Created September 15, 2009 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kossnocorp/187544 to your computer and use it in GitHub Desktop.
Save kossnocorp/187544 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Turbomilker!
// @namespace -
// @include http://turbomilk.ru/*
// ==/UserScript==
// Для начала получим необходимые объекты, и замерим нужные нам велечины
var top_div = document.getElementsByClassName('top_div')[0], // Верхняя плашка
menu_div = document.getElementsByClassName('menu')[0], // Меню
selected = menu_div.getElementsByClassName('selected')[0], // Выбранный пункт
offset_left = top_div.offsetLeft + menu_div.offsetLeft + selected.offsetLeft, // Абсолтютное смещение
// выбранного пункта
bg_offset = offset_left % 4 - 1, // Смещение бекграунда по горизонтали
is_odd = (Math.floor(offset_left / 4) % 2) ? false : true; // Каков порядок клеточек. Четное?
if(is_odd) bg_offset += 4;
// Ровняем позицию бекграунда
// Досадная помеха на на нашем пути :( Жестко выставленна позиция бекграунда в родном CSS,
// посему используем родную Greasemonkey функцию GM_addStyle
// Хотя надо было как то так:
// document.body.style.backgroundPosition = bg_offset_str;
GM_addStyle('#top { background-position: ' + bg_offset.toString() + 'px bottom !important; } ');
GM_addStyle('body { background-position: ' + bg_offset.toString() + 'px 3px !important; } ');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment