Mishi Khanam: Automate Codes - Mishi Marigold

Tuesday, June 24, 2025

Mishi Khanam: Automate Codes

 Ads Codes 





  • Adsterra code: 

2 codes:

1. put 'ad code' ( body, head and paste code)

2. put redirect code (head)



  • Blog:


1. Popunder code (Opens in new tab: Theme

Theme > edit html >


2. Social Bar: Theme

Theme > edit html > 


3. Native Banner: Layout

Layout > kahin b paste kro, best hai k side bar pr put kro link.


Sir Code:

https://aadds01.blogspot.com/p/redirections.html 


Code: Multiple ads… 



✅ Features:

  • 10 iframe ad links (example URLs, replace with real ones)

  • ✅ Popup shows ad for 5 seconds

  • ✅ Every 20 seconds new ad

  • ✅ ❌ Close button to stop

  • ✅ Loop forever

  • ✅ Fully valid HTML (no iframe errors)


✅ What to Do:

  1. Paste this in Blogger body section (Theme > Edit HTML > Just before </body>)

  2. Replace the 10 https://www.exampleX.com with your real ad links that allow iframe

  3. Done 🎉


✅ Final Code (Paste in <body> section)



<style>

  .popup-container {

    display: none;

    position: fixed;

    top: 0; left: 0;

    width: 100%; height: 100%;

    background-color: rgba(0, 0, 0, 0.5);

    justify-content: center;

    align-items: center;

    z-index: 9999;

  }

  .popup {

    background: #fff;

    border-radius: 8px;

    padding: 20px;

    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);

    width: 600px;

    max-width: 90%;

    position: relative;

  }

  .popup iframe {

    width: 100%;

    height: 400px;

    border: none;

  }

  .close-btn {

    position: absolute;

    top: 8px;

    right: 10px;

    background: red;

    color: white;

    border: none;

    border-radius: 4px;

    padding: 5px 10px;

    cursor: pointer;

    font-size: 14px;

  }

</style>


<div class='popup-container' id='popupContainer'>

  <div class='popup'>

    <button class='close-btn' onclick='stopAds()'>❌</button>

    <iframe id='adIframe' src=''></iframe>

  </div>

</div>


<script>

  const popup = document.getElementById('popupContainer');

  const iframe = document.getElementById('adIframe');


  const adUrls = [

    "https://www.example1.com",

    "https://www.example2.com",

    "https://www.example3.com",

    "https://www.example4.com",

    "https://www.example5.com",

    "https://www.example6.com",

    "https://www.example7.com",

    "https://www.example8.com",

    "https://www.example9.com",

    "https://www.example10.com"

  ];


  let adIndex = 0;

  let adLoop = null;

  let adTimeout = null;


  function showAd() {

    iframe.src = adUrls[adIndex];

    popup.style.display = 'flex';


    adTimeout = setTimeout(() => {

      popup.style.display = 'none';

    }, 5000); // show for 5 seconds


    adIndex = (adIndex + 1) % adUrls.length;

  }


  function startLoop() {

    showAd(); // first ad

    adLoop = setInterval(showAd, 20000); // every 20 sec

  }


  function stopAds() {

    clearInterval(adLoop);

    clearTimeout(adTimeout);

    popup.style.display = 'none';

  }


  window.addEventListener("load", () => {

    setTimeout(startLoop, 1000); // start after 1 second

  });

</script>




Google Apps Script



✅ Features Included:

  • ✔️ No rss2json or PHP scraper — pure RSS + internal logic.

  • ✔️ Extracts: title, image, paragraph body.

  • ✔️ Skips short content & redirects.

  • ✔️ Skips already posted articles (duplicate protection).

  • ✔️ 3-second delay between each post.




function fetchAndPostFromFeeds_Final() {
  const blogId = "1835468259577533883"; // ← Apna Blogger ID yahan daalo
  const postedUrls = PropertiesService.getScriptProperties().getProperty("postedUrls") || "[]";
  const alreadyPosted = JSON.parse(postedUrls);

  const feeds = [

 
  "https://news.google.com/rss?hl=en-US&gl=US&ceid=US:en",
  "https://news.google.com/rss/search?q=world+news&hl=en-US&gl=US&ceid=US:en",
  "https://news.google.com/rss/search?q=international+breaking+news&hl=en-US&gl=US&ceid=US:en",
  "https://news.google.com/rss?hl=en&gl=US&ceid=US:en"


];


  const maxPostsPerFeed = 10;
  let newPosted = [];

  for (let feed of feeds) {
    try {
      const xml = UrlFetchApp.fetch(feed, { muteHttpExceptions: true }).getContentText();
      const doc = XmlService.parse(xml);
      const channel = doc.getRootElement().getChild("channel");
      const items = channel.getChildren("item");

      for (let i = 0; i < Math.min(items.length, maxPostsPerFeed); i++) {
        const item = items[i];
        const link = item.getChild("link").getText();

        if (alreadyPosted.includes(link)) {
          Logger.log("⏩ Already posted: " + link);
          continue;
        }

        const pageHtml = UrlFetchApp.fetch(link, { muteHttpExceptions: true }).getContentText();
        const title = item.getChildText("title") || "No Title";

        // ✅ MULTI-PARAGRAPH EXTRACTOR
        const paraMatches = [...pageHtml.matchAll(/<p[^>]*>(.*?)<\/p>/g)];
        let contentParagraphs = [];

        for (let para of paraMatches) {
          const text = para[1].replace(/<[^>]+>/g, '').trim();
          if (text.length > 50 && !text.includes("{") && !text.includes("function")) {
            contentParagraphs.push(`<p>${text}</p>`);
            if (contentParagraphs.length >= 3) break;
          }
        }

        if (contentParagraphs.length < 1) {
          Logger.log("⚠️ Skipped (not enough clean content): " + link);
          continue;
        }

        // ✅ IMAGE FINDER — first valid image (jpg/png/webp), or fallback
        const imageMatches = [...pageHtml.matchAll(/<img[^>]+src="([^"]+)"[^>]*>/gi)];
        let imageSrc = "";

        for (let match of imageMatches) {
          const src = match[1];
          if (/\.(jpg|jpeg|png|webp)/i.test(src)) {
            imageSrc = src;
            break;
          }
        }

        // ✅ Fallback image agar kuch na mile
        if (!imageSrc) {
          imageSrc = "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8ifDv9cfMt5K6RJamiUnxqzbhRhWxch7V37jRfFS-PYPaXUO8yE4cvlLjCaBl8E-I-4oITYnSJU82Du0nenQa2ACwROlNbe_kNY1qqfBb5y2AbpaPp7Raa6zpeP_ehSxLab2nxy8YNglG1nJMKA9OZ6VSygEiCiMKKPAyElDOn_Bgc9WrCCmjdqv3yc2D/s1600/breaking-news-design-template-4bedd10442d6ab8625e47a8412be777e_screen.jpg"; // ← Yahan apni image lagao
        }

        // Add image as clickable link (so user still sees something)
const imageTag = imageSrc
  ? `<a href="${imageSrc}" target="_blank"><img src="${imageSrc}" style="max-width:100%;height:auto;" onerror="this.style.display='none';"></a><br><br>`
  : "";

        const body = `${imageTag}${contentParagraphs.join("")}`;

        const postPayload = JSON.stringify({
          title: title,
          content: body,
          labels: ["News"],
          status: "LIVE"
        });

        const bloggerUrl = `https://www.googleapis.com/blogger/v3/blogs/${blogId}/posts/`;
        const options = {
          method: 'post',
          contentType: 'application/json',
          payload: postPayload,
          headers: {
            Authorization: `Bearer ${ScriptApp.getOAuthToken()}`
          },
          muteHttpExceptions: true
        };

        const response = UrlFetchApp.fetch(bloggerUrl, options);
        Logger.log("✅ Posted: " + title);
        Logger.log("📢 Code: " + response.getResponseCode());

        newPosted.push(link);
        Utilities.sleep(3000); // ⏱ delay
      }

    } catch (err) {
      Logger.log("❌ Feed error: " + feed + " → " + err);
    }
  }

  const updatedPosted = [...alreadyPosted, ...newPosted].slice(-100);
  PropertiesService.getScriptProperties().setProperty("postedUrls", JSON.stringify(updatedPosted));
}
function fetchAndPostFromFeeds_Final() {
  const blogId = "1835468259577533883"; // ← Apna Blogger ID yahan daalo
  const postedUrls = PropertiesService.getScriptProperties().getProperty("postedUrls") || "[]";
  const alreadyPosted = JSON.parse(postedUrls);

 
    const feeds = [

  "https://news.google.com/rss?hl=en-US&gl=US&ceid=US:en",
  "https://news.google.com/rss/search?q=world+news&hl=en-US&gl=US&ceid=US:en",
  "https://news.google.com/rss/search?q=international+breaking+news&hl=en-US&gl=US&ceid=US:en",
  "https://news.google.com/rss?hl=en&gl=US&ceid=US:en",

  "https://www.reutersagency.com/feed/?best-topics=top-news",
  "http://feeds.bbci.co.uk/news/world/rss.xml",
  "http://rss.cnn.com/rss/edition.rss",
  "https://www.aljazeera.com/xml/rss/all.xml",
  "https://www.theguardian.com/world/rss",

  "https://feeds.nbcnews.com/nbcnews/public/news",
  "https://www.cnbc.com/id/100727362/device/rss/rss.html",
  "https://feeds.washingtonpost.com/rss/world",
  "https://feeds.feedburner.com/time/world",
  "https://www.yahoo.com/news/rss/world/",
  "https://feeds.skynews.com/feeds/rss/world.xml",
  "https://www.rt.com/rss/news/",
  "https://feeds.feedburner.com/daily-express-world-news",
  "https://www.scmp.com/rss/91/feed/",
  "https://bbcstoriesnews.blogspot.com/feeds/posts/default?alt=rss"

];


  const maxPostsPerFeed = 10;
  let newPosted = [];

  for (let feed of feeds) {
    try {
      const xml = UrlFetchApp.fetch(feed, { muteHttpExceptions: true }).getContentText();
      const doc = XmlService.parse(xml);
      const channel = doc.getRootElement().getChild("channel");
      const items = channel.getChildren("item");

      for (let i = 0; i < Math.min(items.length, maxPostsPerFeed); i++) {
        const item = items[i];
        const link = item.getChild("link").getText();

        if (alreadyPosted.includes(link)) {
          Logger.log("⏩ Already posted: " + link);
          continue;
        }

        const pageHtml = UrlFetchApp.fetch(link, { muteHttpExceptions: true }).getContentText();
        const title = item.getChildText("title") || "No Title";

        // ✅ MULTI-PARAGRAPH EXTRACTOR
        const paraMatches = [...pageHtml.matchAll(/<p[^>]*>(.*?)<\/p>/g)];
        let contentParagraphs = [];

        for (let para of paraMatches) {
          const text = para[1].replace(/<[^>]+>/g, '').trim();
          if (text.length > 50 && !text.includes("{") && !text.includes("function")) {
            contentParagraphs.push(`<p>${text}</p>`);
            if (contentParagraphs.length >= 3) break;
          }
        }

        if (contentParagraphs.length < 1) {
          Logger.log("⚠️ Skipped (not enough clean content): " + link);
          continue;
        }

        // ✅ IMAGE FINDER — first valid image (jpg/png/webp), or fallback
        const imageMatches = [...pageHtml.matchAll(/<img[^>]+src="([^"]+)"[^>]*>/gi)];
        let imageSrc = "";

        for (let match of imageMatches) {
          const src = match[1];
          if (/\.(jpg|jpeg|png|webp)/i.test(src)) {
            imageSrc = src;
            break;
          }
        }

        // ✅ Fallback image agar kuch na mile
        if (!imageSrc) {
          imageSrc = "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8ifDv9cfMt5K6RJamiUnxqzbhRhWxch7V37jRfFS-PYPaXUO8yE4cvlLjCaBl8E-I-4oITYnSJU82Du0nenQa2ACwROlNbe_kNY1qqfBb5y2AbpaPp7Raa6zpeP_ehSxLab2nxy8YNglG1nJMKA9OZ6VSygEiCiMKKPAyElDOn_Bgc9WrCCmjdqv3yc2D/s1600/breaking-news-design-template-4bedd10442d6ab8625e47a8412be777e_screen.jpg"; // ← Yahan apni image lagao
        }

        const imageTag = `<img src="${imageSrc}" style="max-width:100%;height:auto;"><br><br>`;
        const body = `${imageTag}${contentParagraphs.join("")}`;

        const postPayload = JSON.stringify({
          title: title,
          content: body,
          labels: ["News"],
          status: "LIVE"
        });

        const bloggerUrl = `https://www.googleapis.com/blogger/v3/blogs/${blogId}/posts/`;
        const options = {
          method: 'post',
          contentType: 'application/json',
          payload: postPayload,
          headers: {
            Authorization: `Bearer ${ScriptApp.getOAuthToken()}`
          },
          muteHttpExceptions: true
        };

        const response = UrlFetchApp.fetch(bloggerUrl, options);
        Logger.log("✅ Posted: " + title);
        Logger.log("📢 Code: " + response.getResponseCode());

        newPosted.push(link);
        Utilities.sleep(1000); // ⏱ delay
      }

    } catch (err) {
      Logger.log("❌ Feed error: " + feed + " → " + err);
    }
  }

  const updatedPosted = [...alreadyPosted, ...newPosted].slice(-100);
  PropertiesService.getScriptProperties().setProperty("postedUrls", JSON.stringify(updatedPosted));
}





No comments:

Post a Comment