Notification texts go here Contact Us Buy Now!

Ngăn Adsense ném bom nhấp chuột bằng Vanilla JavaScript - Dựa trên cookie

Xin chào các Blogger! Chào mừng bạn đến với Vietech Blog.

Nếu bạn có một trang web được Adsense phê duyệt, bạn có thể gặp phải các vấn đề về Giới hạn quảng cáo do nhấp chuột không hợp lệ. Adsense có thể hạn chế hiển thị Quảng cáo trên trang web của bạn trong một thời gian giới hạn. Nếu bạn muốn kiểm soát số lần nhấp vào Adsense của khách truy cập, bạn nên thử các mã tôi sắp chia sẻ hôm nay.

Ngăn Adsense ném bom nhấp chuột bằng Vanilla JavaScript dựa trên Cookie

Làm thế nào nó hoạt động?

Về cơ bản, chúng tôi sẽ đặt Cookies trong trình duyệt của khách truy cập với giá trị dựa trên số lần họ đã nhấp vào Quảng cáo. Hãy hiểu với một ví dụ.

Giả sử bạn đã đặt 3 lần nhấp tối đa. Bất cứ khi nào họ nhấp vào Quảng cáo, cookie có khóa mong muốn (tức là "MAX_CLICKS") có giá trị dựa trên số lần nhấp sẽ được đặt trong trình duyệt của họ và giá trị sẽ tăng 1 sau mỗi lần nhấp. Vì vậy, khi họ đạt đến giới hạn (tức là 3 lần) và nhấp lại vào Quảng cáo, quảng cáo sẽ biến mất. Bây giờ, họ sẽ không nhìn thấy bất kỳ Quảng cáo nào trong một khoảng thời gian mà bạn đã đặt.

Xóa cookie sẽ vẫn cho phép người dùng nhấp vào Quảng cáo. Vì vậy, nó sẽ không ngăn chặn hoàn toàn Click Bombing nhưng nó sẽ giúp bạn kiểm soát các nhấp chuột.

Bây giờ thì bắt đầu thôi nào

Bắt đầu

Trước khi chúng tôi bắt đầu thêm mã vào XML, tôi khuyên bạn nên sao lưu chủ đề hiện tại của mình. Tình cờ nếu có vấn đề gì xảy ra, bạn có thể khôi phục lại sau.

Bước 1: Trước hết Đăng nhập vào tài khoản của bạn Trang tổng quan Blogger
Bước 2: Trên Bảng điều khiển Blogger, nhấp vào Chủ đề.
Bước 3: Nhấp vào biểu tượng mũi tên xuống bên cạnh nút 'tùy chỉnh'
Bước 4: Click Edit HTML, bạn sẽ được chuyển đến trang chỉnh sửa.
Bước 5: Bây giờ hãy tìm kiếm mã </head> và dán Mã JavaScript sau đây ngay bên trên vào mã.
<script>
  /*<![CDATA[*/
  /* Cookie functions */
  const Cookie = {
    get: (e) => { e = document.cookie.match(new RegExp("(?:^|; )" + e.replace(/([.$?*|{}()[\]\\/+^])/g, "$1") + "=([^;]*)")); return e ? decodeURIComponent(e[1]) : void 0 },
    set: (e, n, o = {}) => { o = { path: "/", ...o }, o.expires instanceof Date && (o.expires = o.expires.toUTCString()); let c = unescape(encodeURIComponent(e)) + "=" + unescape(encodeURIComponent(n)); for (var t in o) { c += "; " + t; var a = o[t]; !0 !== a && (c += "=" + a) } document.cookie = c },
    rem: (e) => { Cookie.set(e, "", { "max-age": -1 }) }
  }

  /* Anti bomb config */
  const antiBombSet = {
    timeOut: 3600, /* Timeout in seconds, when to ads appear after maximum clicks */
    maxClick: 3, /* No of maximum clicks */
    cookieKey: "MAX_CLICKED", /* Cookie key to set */
    adsSelectors: "ins.adsbygoogle", /* Ads selectors */
    iframeSelectors: "ins.adsbygoogle iframe", /* Ads iframe selectors */
    callback: () => {
      /* Runs only one time if/when clicked maximum times on ads */
      if (antiBombSet.executed === undefined) {
        antiBombSet.executed = !0;

        /* Prevent clicks on ads placement with pointer-events:none | You can also try display:none */
        if (document.getElementById("mxAds_stl") == null) {
          var stl = document.createElement("style");
          stl.id = "mxAds_stl";
          stl.innerHTML = (antiBombSet.adsSelectors || ".adsbygoogle") + "{pointer-events:none}";
          document.head.appendChild(stl);
        }

        /* Add your js below to execute if/when clicked maximum times on ads */
        /* console.warn("You have clicked the maximum times on ads. Don't click on ads if you don't want to support us."); */

      }
    }
  };

  if (Cookie.get(antiBombSet.cookieKey || "ADS_CLICK") != undefined && parseInt(Cookie.get(antiBombSet.cookieKey || "ADS_CLICK")) >= (antiBombSet.maxClick || 3)) {
    antiBombSet.callback()
  };
  /*]]>*/
</script>
Bước 6: Tìm kiếm mã </body> và dán Mã JavaScript sau đây ngay bên trên vào mã.
<script>
  /*<![CDATA[*/
  ! function () {
    function n(e, o) {
      return null != (e = Cookie.get(e)) && parseInt(e) >= o
    }
    var l = antiBombSet.cookieKey || "ADS_CLICK",
      e = antiBombSet.adsSelectors || ".adsbygoogle",
      i = antiBombSet.timeOut || 7200,
      c = antiBombSet.maxClick || 3;
    0 < document.querySelectorAll(e).length && document.querySelectorAll(e).forEach(e => {
      e.addEventListener("click", function () {
        var e, o;
        n(l, c) ? antiBombSet.callback() : (e = l, null != (o = Cookie.get(e)) ? (o = parseInt(o) + 1, Cookie.set(e, o.toString(), {
          secure: !0,
          "max-age": i
        })) : Cookie.set(e, "1", {
          secure: !0,
          "max-age": i
        }))
      })
    }), window.addEventListener("blur", function () {
      n(l, c) && antiBombSet.callback();
      for (var e, o, t = document.querySelectorAll(antiBombSet.iframeSelectors || ".adsbygoogle iframe"), a = 0; a < t.length; a++) document.activeElement == t[a] && (n(l, c) ? antiBombSet.callback() : (e = l, null != (o = Cookie.get(e)) ? (o = parseInt(o) + 1, Cookie.set(e, o.toString(), {
        secure: !0,
        "max-age": i
      })) : Cookie.set(e, "1", {
        secure: !0,
        "max-age": i
      })))
    })
  }();
  /*]]>*/
</script>
Đã Xong!

About the Author

Tôi là một nhà sáng tạo nội dung chuyên nghiệp đến từ Việt Nam. Tôi thích viết mã và tạo ra những điều thú vị khi làm việc với nó.

Đăng nhận xét

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.