Page 1 of 1
Surrogate for repubblica.it
Posted: Tue Mar 05, 2013 7:08 am
by ginola
Hi guys,
I can read the
website of Italian newspaper Repubblica with scripts disabled with no problem, unless I want to browse their galleries. (
example).
As you can see, there's a parameter in the URL pointing to the position of the current picture. I can simply increment that, and it brings me to the next one, so I think the JS is really simple too.
Is somebody able to write a surrogate script that enables browsing galleries?
Thanks!
Re: Surrogate for repubblica.it
Posted: Tue Mar 05, 2013 1:31 pm
by Giorgio Maone
Code: Select all
for (let a of document.querySelectorAll("a[href^='javascript:show']")) a.href = location.href.replace(/\/(\d+)\/?(?:#|$)/, function(m, s) "/" + (parseInt(s) + (/Next/.test(a.href) ? 1 : -1)))
Re: Surrogate for repubblica.it
Posted: Sat Mar 09, 2013 4:53 pm
by ginola
Thanks Giorgio!
And what should the
be? I've tried
but it didn't work.
Is there a FAQ entry on how to write surrogates?
Re: Surrogate for repubblica.it
Posted: Sat Mar 09, 2013 5:11 pm
by Giorgio Maone
ginola wrote:And what should the
be? I've tried
but it didn't work.
"@" is for surrogates running on JavaScript
enabled pages.
If you want a surrogate to run on a JavaScript
disabled page, you need to prepend it with "!",like
ginola wrote:Is there a FAQ entry on how to write surrogates?
A blog post.
Re: Surrogate for repubblica.it
Posted: Sun Mar 10, 2013 8:36 am
by Giorgio Maone
BTW, I slightly adjust the script to handle some edge cases:
Code: Select all
let last = document.head.textContent.match(/\blastPhoto\s*=\s*(\d+)/); last = last && parseInt(last[1]); for (let a of document.querySelectorAll("a[href^='javascript:show']")) a.href = location.href.replace(/\/(\d+)(?=\/?(?:[?#]|$))/, function(m, s) { let n = parseInt(s) + (/Next/.test(a.href) ? 1 : -1); if (n < 1) n = last || 1; else if (last && n > last) n = 1; return "/" + n})