NFC/NEWS1 original page (redirect & ads section skipper)

in Script development
Subscribe to NFC/NEWS1 original page (redirect & ads section skipper) 25 posts, 6 voices



simon! Scriptwright
NFC/NEWS1 original page (redirect & ads section skipper)

Before you start, turn off JavaScript, or use NoScript.

1) : Site's Feed
2) : Feed URL
3) : (redirect) Ad Section
4) : (redirect) Requested Article
5) : Desired Page

1) news1.co.il/Rss/
2) news1.co.il/BringHtmlDoc.aspx?docid=174754&subjectid=1
3) news1.co.il/PageLoad.aspx?adid=3647&pageUrl=Archive/001-D-174754-00.html?tag=14-23-55
4) news1.co.il/Archive/001-D-174754-00.html?tag=14-23-55
5) news1.co.il/Archive/001-D-174754-00.html

how to remove PageLoad.aspx?adid=3647&pageUrl= and ?tag=* ?


- related threads:
?.jpg – Userscripts.org

- related scripts:
Block Meta Refresh – Userscripts.org
YouTube Add &fmt=18 to url – Userscripts.org
YouTube Video Original Page – Userscripts.org
YouTube Video Original Page with Title – Userscripts.org
 
ekbworldwide Scriptwright

// ==UserScript==
// @name           ekb news1.co.il adblocker
// @namespace      ekbworldwide
// @include        http://www.news1.co.il/*
// ==/UserScript==

// I used tmp since I expected to remove the tag string too - but leaving the tag was simpler

if (/\/PageLoad\.aspx\?adid=\d+\&pageUrl\=/.test(location.href)) {
	tmp = location.href.replace(/\/PageLoad\.aspx\?adid=\d+\&pageUrl\=/, "/");
	location.href = tmp;
}

Is that what you want to do?

===

Edit
I'm learning too - I just figured out that using "new RegExp" is better.

// ==UserScript==
// @name           ekb news1.co.il adblocker
// @namespace      ekbworldwide
// @include        http://www.news1.co.il/*
// ==/UserScript==

var t1 = new RegExp(/\/PageLoad\.aspx\?adid=\d+\&pageUrl\=/);
var t2 = new RegExp(/\?tag=.*$/);

if (t1.test(location.href)) {
	tmp = location.href.replace(t1, "/");
	location.href = tmp;
}

 
simon! Scriptwright

Thank you ekb news1.co.il adblocker

Now, how to remove ?tag=* ?

news1.co.il/Archive/001-D-174754-00.html?tag=14-23-55
news1.co.il/Archive/001-D-174754-00.html

 
jerone Scriptwright

if (t2.test(location.href)) {
	tmp = location.href.replace(t2, "/");
	location.href = tmp;
}
@ekbworldwide. Can you tell me why new Regexp is better?

 
simon! Scriptwright

Thanks jerone, but I need these two to work simultaneously - not PageLoad.aspx?adid=3647&pageUrl= and then the script will open the same page without ?tag=*, as it is now...

 
ekbworldwide Scriptwright

@ jerone

My regex stuff has been pretty simple - but if I want to test / match / replace more complex things - and change them on the fly - it's more 'exact' and far easier, simpler and clearer if the regexes are variables.

t1 sure is easier to edit (later) than a least one \/PageLoad\.aspx\?adid=\d+\&pageUrl\=/

 
JoeSimmons Scriptwright

// ==UserScript==
// @name           ekb news1.co.il adblocker
// @namespace      ekbworldwide
// @include        http://www.news1.co.il/*PageLoad.aspx?adid=*
// @include        http://www.news1.co.il/*?tag=*
// ==/UserScript==

var lhref = location.href
var regexp = /(\/PageLoad\.aspx\?adid=\d+(\&pageUrl=.*)*)|([\&\?]tag=.*)/;

if (t1.test(lhref) || t2.test(lhref)) {
location.href = lhref.replace(regexp,'/');
}

 
ekbworldwide Scriptwright

Ah, brevity! [And hmmm...]

 
simon! Scriptwright

thank you all :)

 
simon! Scriptwright

// ==UserScript==
// @name           ekb news1.co.il adblocker
// @description    NEWS1 original page (redirects & ads section skipper)
// @namespace      ekbworldwide
// @include        http://www.news1.co.il/*
// ==/UserScript==

var t1 = new RegExp(/\PageLoad\.aspx\?adid=\d+\&pageUrl\=/);
var t2 = new RegExp(/\?tag=.*$/);

if (t1.test(location.href)) {
	tmp = location.href.replace(t1, "");
	location.href = tmp;
}

if (t2.test(location.href)) {
	tmp = location.href.replace(t2, "");
	location.href = tmp;
}

 
jerone Scriptwright

OffTopic:
@ekbworldwide, You just mean putting the regexp in a variable. Even then you can define it as var t1 = /regexp/;

 
simon! Scriptwright

how to do:

1) IfPageLoad.aspx?adid=3647&pageUrl=And?tag=*Then remove PageLoad.aspx?adid=3647&pageUrl=
1.1) Else If only PageLoad.aspx?adid=3647&pageUrl=Then remove PageLoad.aspx?adid=3647&pageUrl=
1.2) Else If only ?tag=*Then remove ?tag=*

 
znerp Scriptwright

@simon!: I think all the parts of what you've asked for are covered above, and your pseudocode would be easy enough to implement yourself. What's the problem?

 
simon! Scriptwright

the following does not work for me

var t1 = new RegExp(/\PageLoad\.aspx\?adid=\d+\&pageUrl\=/);
var t2 = new RegExp(/\?tag=.*$/);

if (t1.test(location.href)) and (t2.test(location.href)) {
	tmp = location.href.replace(t2, "");
	location.href = tmp;	
}
	
else if (t1.test(location.href)) {
	tmp = location.href.replace(t1, "");
	location.href = tmp;
}

else if (t2.test(location.href)) {
	tmp = location.href.replace(t2, "");
	location.href = tmp;
}

how to tell it "if only" and "and"?

 
Aquilax Scriptwright

Javascript doesn't use words as logical operators.
Here a complete list of all types of operators in javascript.

 
simon! Scriptwright

Thank, Aquilax. This script now works exactly as I desired -- I don't understand why?

Whether the first "IF" will be valid or not, why the script continues to execute the other two commands???

var t1 = new RegExp(/\PageLoad\.aspx\?adid=\d+\&pageUrl\=/);
var t2 = new RegExp(/\?tag=.*$/);

if (t1.test(location.href) + t2.test(location.href)) {
	tmp = location.href.replace(t2, "");
	location.href = tmp;	
	
	if (t1.test(location.href)) {
		tmp = location.href.replace(t1, "");
		location.href = tmp;
		
		if (t2.test(location.href)) {
			tmp = location.href.replace(t2, "");
			location.href = tmp;
		}
	}
}

 
Aquilax Scriptwright


if (location.pathname=="/PageLoad.aspx") location.pathname=/pageUrl=(.*?)(?:\?|$)/.exec(location.search)[1];
if (location.search.indexOf("tag=")!=-1) location.search="";

 
simon! Scriptwright

explain what your code (that you just posted) does...

the code now works perfectly -- but I don't understand the logic?

 
Aquilax Scriptwright

First you have to know that the location object has more properties: location

When you replace one of those properties, with the exception of the hash, the page will be reloaded automatically.

I use some of those properties to get information directly without have to use a regular expression, and when I use it, it's only once.
In your code the regular expressions are executed many times, to deliver always the same result.
Moreover don't use + but && in the if conditions, this is the correct way to build a logical expression.

 
simon! Scriptwright

Man, this is tough... the last time I was dealing with thing like this was 3 years ago at my High-School learning Pascal and C++ (or C# ???)

Btw, I just tried your code -- it's the best, so far ;)

edit: only when you switch the lines:

if (location.search.indexOf("tag=")!=-1) location.search="";
if (location.pathname=="/PageLoad.aspx") location.pathname=/pageUrl=(.*?)(?:\?|$)/.exec(location.search)[1];

 
JoeSimmons Scriptwright

Oops. A little flaw in mine.... here's working code I believe...

// ==UserScript==
// @name           ekb news1.co.il adblocker
// @namespace      ekbworldwide
// @include        http://www.news1.co.il/*PageLoad.aspx?adid=*
// @include        http://www.news1.co.il/*?tag=*
// ==/UserScript==

var lhref = location.href
var regexp = /(\/PageLoad\.aspx\?adid=\d+(\&pageUrl=.*)*)|([\&\?]tag=.*)/;

if (regexp.test(lhref)) {
location.href = lhref.replace(regexp,'/');
}

 
simon! Scriptwright

It is redirecting me to the main page

and about the tag=* (see this screenshot)

 
znerp Scriptwright
1) IfPageLoad.aspx?adid=3647&pageUrl=And?tag=*Then remove PageLoad.aspx?adid=3647&pageUrl=
1.1) Else If only PageLoad.aspx?adid=3647&pageUrl=Then remove PageLoad.aspx?adid=3647&pageUrl=
1.2) Else If only ?tag=*Then remove ?tag=*
Try this...
if (/\PageLoad\.aspx\?adid=\d+\&pageUrl\=/.test(location.href))
  document.location.replace(location.href.replace(/\PageLoad\.aspx\?adid=\d+\&pageUrl\=/, "").replace(/\?tag=.*$/, ""))
else if (/\?tag=.*$/.test(location.href))
  document.location.replace(location.href.replace(/\?tag=.*$/, ""))
 
simon! Scriptwright

thank you very much for your effort (it works fine, also), but I really think that this code is fine enough for what I wish for ^_^

edit: btw, I was wrong here

1) IfPageLoad.aspx?adid=3647&pageUrl=And?tag=*Then remove PageLoad.aspx?adid=3647&pageUrl=
1.1) Else If only ?tag=*Then remove ?tag=*
1.2) Else If only PageLoad.aspx?adid=3647&pageUrl=Then remove PageLoad.aspx?adid=3647&pageUrl=

 
JoeSimmons Scriptwright

Ok I see what you want now. Use this...

// ==UserScript==
// @name           ekb news1.co.il adblocker
// @namespace      ekbworldwide
// @include        http://www.news1.co.il/*PageLoad.aspx?adid=*
// @include        http://www.news1.co.il/*?tag=*
// ==/UserScript==

var lhref = location.href;
var pageload = /\/PageLoad\.aspx\?adid=\d+\&pageUrl=/;
var tag = /\?tag=.*/;

if (pageload.test(lhref) || tag.test(lhref)) {
location.href = lhref.replace(pageload,'/').replace(tag,'');
}

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel