d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Make Me A Better Programmer - From Step 2
Prev1234510Next
Add Reply New Topic New Poll
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Nov 27 2014 01:54am
Quote (carteblanche @ Nov 27 2014 02:52am)
that's the point :P


i edited...was I on the right track!?
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 27 2014 01:57am
Quote (Eep @ Nov 27 2014 02:54am)
i edited...was I on the right track!?


did you miss the part where i dont know jquery either? lol. i forgot that i used it briefly a year ago to start building my own skin for youtube subscription videos, but i dont have any real experience with it. i just googled to figure out how to get the original script working. gonna google more to learn how to crawl up/down the hierarchy.

$('criteria') finds elements that meet the criteria. i know that much. it's gonna be a learning experience.
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Nov 27 2014 02:03am
Quote (carteblanche @ Nov 27 2014 02:57am)
did you miss the part where i dont know jquery either? lol. i forgot that i used it briefly a year ago to start building my own skin for youtube subscription videos, but i dont have any real experience with it. i just googled to figure out how to get the original script working. gonna google more to learn how to crawl up/down the hierarchy.

$('criteria') finds elements that meet the criteria. i know that much. it's gonna be a learning experience.


Ohhh shit I didn't see that actually lol.

I found this online

Code
var elementsWithLinks = $('a[href="some-link.com"]')



though this assumes you want to change every element with that href I am guessing.

when you say crawl up I am guessing that is a better method (finding actual posts, not just links at the top of the page etc)

This post was edited by Eep on Nov 27 2014 02:06am
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Nov 27 2014 02:04am
Quote (carteblanche @ Nov 27 2014 01:35am)
you better not be fixing it...that's for Eep!



I'm just a bystander. Enjoying the conversation.
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Nov 27 2014 02:16am
there is a parent -> child selector, wonder if something like

Code
var elementsWithLinks = $('dt > a[href="some-link.com"]')


would work

though, when you say fix all the <span>, I am a little confused...it seems that posts are done in divs afaik
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 27 2014 02:22am
Code
// ==UserScript==
// @name Fix NekoSama's posts
// @namespace http://your.homepage/
// @version 0.1
// @description Changes NekoSama's font to normal black instead of giant green
// @author carteblanche
// @match http://forums.d2jsp.org/topic.php*
// @grant none
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==

$(document).ready(function() {
// fix all of nekosama's posts no matter what font/colour he uses
var a = $('a').filter(function(){
// find nekosama by his id; dont want him circumventing by changing his name
return $(this).attr('href') == 'user.php?i=434436';
});
if (a.length > 0){
// found him. now grab the element's grandparent
var dt = a.parent();
var dl = dt.parent();
// now find all <span> children
var spans = dl.find('span');
if (spans.length > 0){
spans.css('color', 'rgb(0,0,0)');
spans.css('font-size', '8pt');
}
}
});


that was pretty easy, using .parent() and .find(..)

Quote (Eep @ Nov 27 2014 03:16am)
there is a parent -> child selector, wonder if something like

Code
var elementsWithLinks = $('dt > a[href="some-link.com"]')


would work

though, when you say fix all the <span>, I am a little confused...it seems that posts are done in divs afaik


looks like the > only grabs the direct child, whereas find() will go through all descendants.

they are in divs i think, but <span> is used to change font styling. the dev tools in chrome are super helpful

This post was edited by carteblanche on Nov 27 2014 02:25am
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Nov 27 2014 02:27am
Quote (carteblanche @ Nov 27 2014 03:22am)
Code
// ==UserScript==
// @name        Fix NekoSama's posts
// @namespace    http://your.homepage/
// @version      0.1
// @description  Changes NekoSama's font to normal black instead of giant green
// @author      carteblanche
// @match        http://forums.d2jsp.org/topic.php*
// @grant        none
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==

$(document).ready(function() {
    // fix all of nekosama's posts no matter what font/colour he uses
    var a = $('a').filter(function(){
      // find nekosama by his id; dont want him circumventing by changing his name
      return $(this).attr('href') == 'user.php?i=434436';
    });
    if (a.length > 0){
        // found him. now grab the element's grandparent
        var dt = a.parent();
        var dl = dt.parent();
        // now find all <span> children
        var spans = dl.find('span');
        if (spans.length > 0){
            spans.css('color', 'rgb(0,0,0)');
            spans.css('font-size', '8pt');
        }
    }
});


that was pretty easy, using .parent() and .find(..)



looks like the > only grabs the direct child, whereas find() will go through all descendants.

they are in divs i think, but <span> is used to change font styling.


ahhh. That is pretty neat. Jquery such power etc.


also, the real pressing question: who is nekosama o.o
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 27 2014 02:30am
Quote (Eep @ Nov 27 2014 03:27am)
ahhh. That is pretty neat. Jquery such power etc.


also, the real pressing question: who is nekosama o.o


GC user who makes nonsense topics and spams with his huge font getting in everyone's way.

http://forums.d2jsp.org/user.php?i=434436&c=41

considering making a script to hide topics by user. AnimeFTW has a script that blocks user posts, but not their topics.
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Nov 27 2014 02:32am
Quote (carteblanche @ Nov 27 2014 03:30am)
GC user who makes nonsense topics and spams with his huge font getting in everyone's way.

http://forums.d2jsp.org/user.php?i=434436&c=41

considering making a script to hide topics by user. AnimeFTW has a script that blocks user posts, but not their topics.


that should just be a feature on the site lol
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Nov 27 2014 04:33am
oh, I realized something.

I was checking posts on this thread for the spans in question....I think they only show up when you are doing crazy font shit.

That would explain why I couldn't find them :o

edit:

herpderp

This post was edited by Eep on Nov 27 2014 04:34am
Go Back To Programming & Development Topic List
Prev1234510Next
Add Reply New Topic New Poll