Discussions » Creation Requests

improve a little script

§
Posted: 2015-08-28

improve a little script

hi all, so i have a script
$("tr:contains(Windows 10)").find("img[src*='unlockednew.gif']").attr('src', 'http://i.imgur.com/n4oOWSA.png');
$("tr:contains(Windows 10)").find("img[src*='unlocked.gif']").attr('src', 'http://i.imgur.com/8caN3eq.png');

$("tr:contains(-=TOP ACHTUNG=-)").find("img[src*='unlockednew.gif']").attr('src', 'http://i.imgur.com/MZvfeBZ.png');
$("tr:contains(-=TOP ACHTUNG=-)").find("img[src*='unlocked.gif']").attr('src', 'http://i.imgur.com/6sIlg6a.png');

$("tr:contains(Post Your Gameplay)").find("img[src*='unlockednew.gif']").attr('src', 'http://i.imgur.com/przfX4Y.png');
$("tr:contains(Post Your Gameplay)").find("img[src*='unlocked.gif']").attr('src', 'http://i.imgur.com/o9nYHbD.png');

$("tr:contains(Probleme cu Hardware)").find("img[src*='unlockednew.gif']").attr('src', 'http://i.imgur.com/tt14C3s.png');
$("tr:contains(Probleme cu Hardware)").find("img[src*='unlocked.gif']").attr('src', 'http://i.imgur.com/sFs4gX4.png');

$("tr:contains(Windows 7)").find("img[src*='unlockednew.gif']").attr('src', 'http://i.imgur.com/EENLvOV.png');
$("tr:contains(Windows 7)").find("img[src*='unlocked.gif']").attr('src', 'http://i.imgur.com/CICqHS1.png');

$("tr:contains(Grand Theft Auto V)").find("img[src*='unlockednew.gif']").attr('src', 'http://i.imgur.com/zerAX3j.png');
$("tr:contains(Grand Theft Auto V)").find("img[src*='unlocked.gif']").attr('src', 'http://i.imgur.com/hDiKqOp.png');

$("tr:contains(Google Chrome)").find("img[src*='unlockednew.gif']").attr('src', 'http://i.imgur.com/Iravyh3.png');
$("tr:contains(Google Chrome)").find("img[src*='unlocked.gif']").attr('src', 'http://i.imgur.com/diCqwTa.png');

$("tr:contains(Sugestii şi idei)").find("img[src*='unlockednew.gif']").attr('src', 'http://i.imgur.com/kfL3R0o.png');
$("tr:contains(Sugestii şi idei)").find("img[src*='unlocked.gif']").attr('src', 'http://i.imgur.com/YgFY8mF.png');


the script is working but how can i improve it, i think you will understand me, thank you

wOxxOmMod
§
Posted: 2015-08-28

If it ain't broke don't fix it

So what is the actual problem?

§
Posted: 2015-08-28

but i wish i could do someting like this

var topics = [
{
name: "Windows 10",
unreadUrl: "http://i.imgur.com/n4oOWSA.png",
readUrl: "http://i.imgur.com/8caN3eq.png"
},
{
name: "-=TOP ACHTUNG=-"
unreadUrl: "link to icon",
readUrl: "link to icon"
},
// ...
];

topics.forEach(function(topic) {

$("tr:contains(topic.name)")
.find("img[src*='unlockednew.gif']").attr('src', topic.unreadUrl);

$("tr:contains(topic.name)")
.find("img[src*='unlocked.gif']").attr('src', topic.readUrl);
});

but i get a error

wOxxOmMod
§
Posted: 2015-08-28
Edited: 2015-08-28
  • remove ; at the end of the first readUrl: line
  • add , at the end of the second name: line
  • use http://jshint.com/ to check the code if your text editor doesn't have jshint/jslint
§
Posted: 2015-08-28

oh, that page is good, thank you!

Post reply

Sign in to post a reply.