Discussions » Creation Requests

Need help with a simple script

§
Posted: 2014-06-29

Need help with a simple script

I just want to set the attributes of en element from fixed to relative idk what im doing wrong


// ==UserScript==
// @name Reyanime no fixed bars
// @version 1.0
// @author Roxz
// @description Hace que las barras no se muevan al hacer scroll
// @include http://reyanime.com/*
// @include https://reyanime.com/*
// ==/UserScript==


function () {
var barra = document.getElementById("top-barra"),
negro = document.getElementById("negro"),
blue = document.getElementById("izq-blue-fixed");

barra.style.position = "relative";
negro.style.position = "relative";
blue.style.position = "relative";

})();

§
Posted: 2014-06-29
Edited: 2014-06-29

Missing '(' before function (). Needs to be (function () { script })();

§
Posted: 2014-06-29

(function () {
var barra = document.getElementById("top-barra"),
negro = document.getElementById("negro"),
blue = document.getElementById("izq-blue-fixed");

barra.style.position = "relative";
negro.style.position = "relative";
blue.style.position = "relative";

})();

Like that? Cause it's not working either.

§
Posted: 2014-06-29

Try:

(function () {
var barra = document.querySelector(".top-barra"),
negro = document.querySelector(".negro"),
blue = document.querySelector(".izq-blue-fixed");

barra.style.position = "relative";
negro.style.position = "relative";
blue.style.position = "relative";

})();

§
Posted: 2014-06-29

That worked. Thanks. Whats the difference between getElementById and queryselector? When do you use querySelector?

§
Posted: 2014-06-29
Edited: 2014-06-29

The elements you wanted to target have no id name, only a class name.

§
Posted: 2014-06-29

Thanks. I keep testing it and it doesnt work consistently on some subdomains the "negro" stays fixed does that happen cause not all the var are all together on the same page?

§
Posted: 2014-06-29

Give me the url for which that occurs on and I will check it out.

§
Posted: 2014-06-29

for example http://reyanime.com/dokidoki-precure-la-pelicula-1/

I made a separate script just with the var negro and it works on that page but if I add the rest of the vars it doesnt.

§
Posted: 2014-06-29
Edited: 2014-06-29

Try this:

(function () {
var negro = document.querySelector(".negro"),
barra = document.querySelector(".top-barra"),
blue = document.querySelector(".izq-blue-fixed");

if (negro) negro.style.position = "relative";
if (barra) barra.style.position = "relative";
if (blue) blue.style.position = "relative";

})();

Edit:
Also try this // @include http://reyanime* instead of // @include http://reyanime.com/*
Will include more pages.

§
Posted: 2014-06-29

Thanks again. I tried the if thing but i guess my syntax was off.

§
Posted: 2014-06-29
Edited: 2014-06-29

If using Greasemonkey 0.9.8 or above, try this (copy/paste):

// ==UserScript==
// @name Reyanime no fixed bars
// @version 1.0
// @author Roxz
// @description Hace que las barras no se muevan al hacer scroll
// @include /^https?://reyanime.*$/
// @grant none
// ==/UserScript==

(function () {
var negro = document.querySelector(".negro"),
barra = document.querySelector(".top-barra"),
blue = document.querySelector(".izq-blue-fixed");

if (negro) negro.style.position = "relative";
if (barra) barra.style.position = "relative";
if (blue) blue.style.position = "relative";

})();

§
Posted: 2014-06-30

Or, you can do it with style injection:

// ==UserScript==
// @name Reyanime no fixed bars
// @version 1.0
// @author Roxz
// @description Hace que las barras no se muevan al hacer scroll
// @include http://reyanime.com/*
// @include https://reyanime.com/*
// ==/UserScript==

(function () {
	var $css = document.createElement ('style');
	$css.textContent = '\
	.top-barra,.negro,.izq-blue-fixed {\
		position:relative !important;\
	}';
	document.head.appendChild ($css);
})();
§
Posted: 2014-07-06

Thanks both guys. Since my last comment the issue was alrready solved.

Post reply

Sign in to post a reply.