Pages:
Author

Topic: Signature Adblock Script [0.5.0] - page 5. (Read 37472 times)

legendary
Activity: 966
Merit: 1000
April 08, 2015, 06:13:31 AM
#59
However, was there not a option to disable all signatures?
Even If I'm sure you already know this:
"Profile" -> "Look and Layout Preferences" -> "Don't show users' signatures."
That isn't thr thing everyone wants. Me as an example, i want to see user signatures and most of other people want too, they just don't want to see the AD ones.
hero member
Activity: 686
Merit: 500
FUN > ROI
April 08, 2015, 05:28:49 AM
#58
Your annotated code is actually pretty close to the original source!
sweet! Smiley

Thanks for the reply, so we should open a thread and ask to theymos if he can add this script here in the forum.
Keep in mind that if the javascript code is added to the forum, it also needs somebody to maintain it, and you can't make your own tweaks (e.g. to the scoring algorithm)

I'm also not sure that's really the way to go versus a signature ignore boolean of some variety.  There's pros and cons (dev time, upkeep, (false) positives, user control, server load, etc.) to both approaches though.
legendary
Activity: 1778
Merit: 1043
#Free market
April 08, 2015, 04:32:32 AM
#57
Can I ask if there will be the possibility to integrate that script here in this forum (without using an external extension)? Thanks for the attention.
One way would be to create a forum theme that contains my script. That way it's available to every user and can be enabled/disabled from the user control panel. You'll have to petition theymos to do that though.

Another way (which I mentioned before), would be to use a proxy that injects the script.

Thanks for the reply, so we should open a thread and ask to theymos if he can add this script here in the forum. I think someone of us will do this (when it will be necessary). The second option is more "risky" than the first, or am I wrong? Maybe it is better the first option.
hero member
Activity: 910
Merit: 1000
April 08, 2015, 04:09:36 AM
#56
too bad i don't like java, why not choosing other programming language? can this be done in php or python?
This is not Java, this is Javascript.

Either way, choose the best tool for the job. I know it's not, but even if it were Java, not "liking" something shouldn't be the disqualifying feature when it comes to choosing a development technology.
copper member
Activity: 3948
Merit: 2201
Verified awesomeness ✔
April 08, 2015, 03:02:14 AM
#55
too bad i don't like java, why not choosing other programming language? can this be done in php or python?
This is not Java, this is Javascript.
legendary
Activity: 3248
Merit: 1070
April 08, 2015, 02:53:29 AM
#54
too bad i don't like java, why not choosing other programming language? can this be done in php or python?
legendary
Activity: 2058
Merit: 1452
April 07, 2015, 11:44:28 PM
#53
If you cannot read this, original source code wont change anything!
That's a wee bit unfair - Just because somebody doesn't know what to make of...
Code:
$(e).find("a").length && (r *= 2)
...doesn't mean they won't know what this does:
Code:
if ($(element).find("a").length > 0) { score = score * 2 }
And the minified code - though possibly even the input - makes use of quite a few such tricks and programmer shorthands.
refactored+annotated (making no claim that it still works, or even that I got it right - I certainly wouldn't use it): http://pastebin.com/CTXaCnkp

But for most people with concerns, this is the only bit of code that does anything they should care about:
Code:
$(i[a]).attr("style", "opacity: 0; pointer-events: none")
All it does is make the entire signature fully transparent and unresponsive to clicks/taps, and that bit of code is only called if the signature scores badly.  There's certainly no communication with a mothership or secret background bitcoin mining on your CPU etc. going on. (as of this post)

Your annotated code is actually pretty close to the original source! The main reason I use mimify the script with uglifyjs is because it removes my debug statements, which there are a lot of. In the interest of openness, here is a version that has minimal uglification applied to it: bct_adblock.no_debug.js. The creation and upload of the not-so-minified version is built into my upload scripts so it should be up to date with any future updates.

For reference, below is the original source, with debugging removed. If you want to understand how the script works, TheRealSteve is the way to go because it has annotations.
Code:
function isAnnoyingCharacter(char)
{
  var code = char.charCodeAt();
  var ranges = [[0x2500, 0x256F],
                [0x2580, 0x259F],
                [0x25A0, 0x25FF],
               ];
  for(var i = 0; i < ranges.length; i++)
    if(code > ranges[i][0] && code <= ranges[i][1])
      return true;
  return false;
}

function calculateAnnoyingCharacter(element)
{
  var childNodes = Array.prototype.slice.call(element.childNodes);
  var result = childNodes.reduce(
    function(prev, current, index)
    {
      if(current.nodeType == 1)
        return prev + calculateAnnoyingCharacter(current);
      if(current.nodeType == 3)
      {
        var count = 0;
        for (c of current.nodeValue)
          if(isAnnoyingCharacter(c))
            count++;

        var size = Number(getComputedStyle(current.parentNode).fontSize.match(/(\d*(\.\d*)?)px/)[1]);
        return prev + size*size*count;
      }
      return prev;
    }, 0);
  return result;
}

function getFormattingRate(context)
{
  var result = 0;
  if(context.backgroundColor)
    return 1;
  if(context.fontSize >= 14)
    result += 0.05 + Math.max(0, (context.fontsize - 14)*0.03);
  if(context.color)
    result += 0.2;
  if(context.font)
    result += 0.03;
  if(context.underline)
    result += 0.02;
  if(context.bold)
    result += 0.04;
  if(context.table)
    result += 0.2;
  return Math.min(result, 1);
}


function calculateFormattingScore(element, context)
{
  var previousContext = context;
  if(typeof(context) === 'undefined')
    previousContext = context = {};
  else
    context = $.extend({}, context);

  if(element.style.fontSize && element.style.fontSize != "inherit")
    context.fontsize = Number(element.style.fontSize.match(/(\d+)pt/)[1]);

  if(element.style.color && element.style.color != "inherit")
    context.color = true;
  
  if(element.style.backgroundColor && element.style.backgroundColor != "inherit")
    context.backgroundColor = true;
  
  if(element.style.fontFamily && element.style.fontFamily != "inherit")
    context.font = true;
  
  if(element.style.textDecoration.indexOf("underline") != -1)
    context.underline = true;
  
  if(element.tagName == "B")
    context.bold = true;
  
  if(element.tagName == "TABLE")
    context.table = true;
  
  var score = $(element).width() * $(element).height() * getFormattingRate(context)
              - $(element).width() * $(element).height() * getFormattingRate(previousContext);

  var childNodes = Array.prototype.slice.call(element.childNodes);
  score += childNodes.reduce(
    function(prev, current, index)
    {
      if(current.nodeType == 1)
        return prev + calculateFormattingScore(current, context);
      return prev;
    }, 0);
  return score;
}

function isAd(div)
{
  var score = 0;
  score += calculateAnnoyingCharacter(div);
  score += calculateFormattingScore(div);
  score = Math.sqrt(score);
  if($(div).find("a").length)
    score *= 2;
  
  return score > 100;
};

try
{
  var signatures = $("div .signature");
  for(var i = 0; i < signatures.length; i++)
  {
    if(isAd(signatures[i]))
    {
        $(signatures[i]).attr("style", "opacity: 0; pointer-events: none");
    }
  }
}
catch(e)
{
  console.log(e);
}
hero member
Activity: 686
Merit: 500
FUN > ROI
April 07, 2015, 10:19:54 PM
#52
If you cannot read this, original source code wont change anything!
That's a wee bit unfair - Just because somebody doesn't know what to make of...
Code:
$(e).find("a").length && (r *= 2)
...doesn't mean they won't know what this does:
Code:
if ($(element).find("a").length > 0) { score = score * 2 }
And the minified code - though possibly even the input - makes use of quite a few such tricks and programmer shorthands.
refactored+annotated (making no claim that it still works, or even that I got it right - I certainly wouldn't use it): http://pastebin.com/CTXaCnkp

But for most people with concerns, this is the only bit of code that does anything they should care about:
Code:
$(i[a]).attr("style", "opacity: 0; pointer-events: none")
All it does is make the entire signature fully transparent and unresponsive to clicks/taps, and that bit of code is only called if the signature scores badly.  There's certainly no communication with a mothership or secret background bitcoin mining on your CPU etc. going on. (as of this post)
legendary
Activity: 1974
Merit: 1029
April 07, 2015, 03:49:14 PM
#51
I don't trust your js code.
It's non human readable.

Share original source code.

Uh, there's no such thing as compiled javascript (I know someone will correct me if I'm wrong), so I have to wonder what the hell you're talking about here.+

Not compiled but minified, which makes it harder to follow. He's asking for the non-minified version.
legendary
Activity: 2058
Merit: 1452
April 07, 2015, 11:37:34 AM
#50
Can I ask if there will be the possibility to integrate that script here in this forum (without using an external extension)? Thanks for the attention.
One way would be to create a forum theme that contains my script. That way it's available to every user and can be enabled/disabled from the user control panel. You'll have to petition theymos to do that though.

Another way (which I mentioned before), would be to use a proxy that injects the script.
legendary
Activity: 1778
Merit: 1043
#Free market
April 07, 2015, 03:50:41 AM
#49
Can I ask if there will be the possibility to integrate that script here in this forum (without using an external extension)? Thanks for the attention.
sed
hero member
Activity: 532
Merit: 500
April 07, 2015, 12:58:34 AM
#48
I don't trust your js code.
It's non human readable.

Share original source code.

Uh, there's no such thing as compiled javascript (I know someone will correct me if I'm wrong), so I have to wonder what the hell you're talking about here.


I feel like we are treading on thin ice here. Our forum is so unique and we created system of direct advertising method that is unprecedented and  truly "sui generis". Yet you want to destroy that system by creating tools and methods which will disable signatures permanently? Potentially it can bring an end to all signature campaigns.

The forum isn't about advertising, its about discussion. Businesses that advertise in people's signatures have the same right to be here and the same right to be kicked out if they are disruptive. If individuals want to opt out of seeing advertisements they are more than welcome to, and if that brings down paid advertising signatures, then so be it.

But I agree, great job grue.

Indeed, I appreciate the approach here, people taking control to limit what they want to see, obviously this is a win.  If advertizers annoy, they should be punished by people ignoring them.  That will teach them to annoy less.  Ie, be less distracting.

Wil I be shot for irony if I try this script myself?
legendary
Activity: 3836
Merit: 4969
Doomed to see the future and unable to prevent it
April 06, 2015, 10:07:32 PM
#47
Neat tool, nice to have. Personally I never really minded the sig ads that much. I am more bothered by the low quality/irrelevant/spammy posts that the sig ads/campaigns unintentionally promote to these forums.

When I decide whether to ignore someone the Sig can be the deciding factor.
hero member
Activity: 868
Merit: 1001
https://keybase.io/masterp FREE Escrow Service
April 06, 2015, 07:44:40 PM
#46
Neat tool, nice to have. Personally I never really minded the sig ads that much. I am more bothered by the low quality/irrelevant/spammy posts that the sig ads/campaigns unintentionally promote to these forums.
hero member
Activity: 672
Merit: 500
hero member
Activity: 658
Merit: 500
March 28, 2015, 11:31:22 AM
#44
You can theoretically get it to work by using a proxy that inserts the javascript into every page that you load. I'm planning on implementing a bitcointalk proxy with 2-factor authentication and other security features, so there's that  Smiley

Yes, that would be nice, as long as it's secure.
copper member
Activity: 3948
Merit: 2201
Verified awesomeness ✔
March 28, 2015, 11:26:27 AM
#43
You can theoretically get it to work by using a proxy that inserts the javascript into every page that you load. I'm planning on implementing a bitcointalk proxy with 2-factor authentication and other security features, so there's that  Smiley
Sign me up! That is extremely handy.
legendary
Activity: 2058
Merit: 1452
March 28, 2015, 11:08:31 AM
#42
You can theoretically get it to work by using a proxy that inserts the javascript into every page that you load. I'm planning on implementing a bitcointalk proxy with 2-factor authentication and other security features, so there's that  Smiley
hero member
Activity: 658
Merit: 500
March 28, 2015, 09:18:54 AM
#41
This is awesome. Too bad I can't use it on my mobile Sad

I though it can work to mobile too since I'm still not try it

Thanks for a new update..everything works perfect

It can't work on Windows Phone because it doesn't have addons.
legendary
Activity: 1218
Merit: 1001
March 28, 2015, 04:52:59 AM
#40
This is awesome. Too bad I can't use it on my mobile Sad

I though it can work to mobile too since I'm still not try it

Thanks for a new update..everything works perfect
Pages:
Jump to: