xgqfrms / learning

learning : A collection of all kinds of resources, videos, pdf, blogs, codes... 📚 + 💻 + ❤
https://learning.xgqfrms.xyz
MIT License
16 stars 12 forks source link

Chrome 插件套路 #142

Open xgqfrms opened 1 year ago

xgqfrms commented 1 year ago

Chrome 插件套路

1.获取自定义 URL flag

  1. 请求后端 API 数据
  2. VIP 付费解锁

image

image

demo

https://leetcode.com/problemset/all/ https://leetcode.com/problems/string-to-integer-atoi/?show=1


var u = [];
function e(t) {
  chrome.tabs.query({
    active: !0,
    currentWindow: !0
  }, function(e) {
    t && t(e.length ? e[0].id : null)
  })
}
function t(t, o) {
  e(e=>{
    chrome.tabs.sendMessage(e, t, function(e) {
      o && o(e)
    })
  }
  )
}
chrome.storage.local.get({
  cur_version: "red"
}, function(e) {
  const d = e.cur_version;
  $("#cur_version").text(`${d}`),
  chrome.storage.local.get({
    meta_v2: "red"
  }, function(e) {
    var t = e.meta_v2.version || "拉取失败,请尝试点击「手动刷新数据」按钮"
      , o = e.meta_v2.pdf_version || "拉取失败";
    const n = e.meta_v2.release_url || "https://mp.weixin.qq.com/s/wIxflO1dvXzDlibhEcENcQ";
    var c = e.meta_v2.notify_line || "更多功能敬请期待……"
      , a = e.meta_v2.vs_version || "拉取失败"
      , r = e.meta_v2.jb_version || "拉取失败"
      , i = e.meta_v2.ds_version || "拉取失败"
      , l = e.meta_v2.challenge_version || "拉取失败";
    $("#notify_line").html(c),
    $("#latest_version").text(`${t}`),
    $("#pdf_latest_version").text(`${o}`),
    $("#vscode_latest_version").text(`${a}`),
    $("#jb_latest_version").text(`${r}`),
    $("#ds_latest_version").text(`${i}`),
    $("#challenge_latest_version").text(`${l}`),
    t > d && (chrome.action.setBadgeText({
      text: "new"
    }),
    $("#latest_version").after('<button id="download_link" value="按钮">更新</button>').after($("<p>本次更新修复了已知 bug 并添加了更多实用功能,建议所有用户升级:</p>")),
    $("#download_link").click(()=>{
      chrome.tabs.create({
        url: n
      })
    }
    ));
    e = e.meta_v2.guide_url || "https://mp.weixin.qq.com/s/wIxflO1dvXzDlibhEcENcQ";
    $("#guide").attr("href", e);
    let s = $("#refresh_btn");
    s.on("click", ()=>{
      $("#refresh_status").text(""),
      u = [],
      chrome.runtime.sendMessage({
        cmd: "update_data"
      })
    }
    ),
    $("#refresh_btn").append(s)
  })
}),
chrome.runtime.onMessage.addListener(function(n, e, t) {
  if ("brief" === n.statusType) {
    console.log(n);
    var c = n.file.split(".")[0].split("_")[0];
    if (!u.includes(c)) {
      u.push(c);
      let o = c + n.status + "; ";
      if (n.hasOwnProperty("xe_id")) {
        let e = n.xe_id
          , t = `https://appktavsiei5995.pc.xiaoe-tech.com/detail/${e}/1`;
        e.startsWith("p_") && (t = `https://appktavsiei5995.pc.xiaoe-tech.com/detail/${e}/8`),
        o = `<a href='${t}' target="_blank">${o}</a>`
      }
      $("#refresh_status").append(`<span>${o}</span>`)
    }
  }
}),
$("#open_background").click(e=>{
  window.open(chrome.extension.getURL("background.html"))
}
),
$("#invoke_background_js").click(e=>{
  chrome.extension.getBackgroundPage().testBackground()
}
),
$("#get_background_title").click(e=>{
  var t = chrome.extension.getBackgroundPage();
  alert(t.document.title)
}
),
$("#set_background_title").click(e=>{
  var t = prompt(".leetcode.labuladong.background.leetcode.labuladong.:", ".leetcode.labuladong.");
  chrome.extension.getBackgroundPage().document.title = t,
  alert(".leetcode.labuladong.!")
}
),
$("#custom_window_size").click(()=>{
  chrome.windows.getCurrent({}, e=>{
    var t = 10;
    chrome.windows.update(e.id, {
      left: 10 * t,
      top: 100,
      width: 800,
      height: 600
    });
    var o = setInterval(()=>{
      40 <= t && clearInterval(o),
      chrome.windows.update(e.id, {
        left: 10 * ++t
      })
    }
    , 50)
  }
  )
}
),
$("#max_current_window").click(()=>{
  chrome.windows.getCurrent({}, e=>{
    chrome.windows.update(e.id, {
      state: "maximized"
    })
  }
  )
}
),
$("#min_current_window").click(()=>{
  chrome.windows.getCurrent({}, e=>{
    chrome.windows.update(e.id, {
      state: "minimized"
    })
  }
  )
}
),
$("#open_new_window").click(()=>{
  chrome.windows.create({
    state: "maximized"
  })
}
),
$("#close_current_window").click(()=>{
  chrome.windows.getCurrent({}, e=>{
    chrome.windows.remove(e.id)
  }
  )
}
),
$("#open_url_new_tab").click(()=>{
  chrome.tabs.create({
    url: "https://www.baidu.com"
  })
}
),
$("#open_url_current_tab").click(()=>{
  e(e=>{
    chrome.tabs.update(e, {
      url: "http://www.so.com"
    })
  }
  )
}
),
$("#get_current_tab_id").click(()=>{
  e(e=>{
    alert(".leetcode.labuladong.ID:" + e)
  }
  )
}
),
$("#highlight_tab").click(()=>{
  chrome.tabs.highlight({
    tabs: 0
  })
}
),
$("#send_message_to_content_script").click(()=>{
  t(".leetcode.labuladong.,.leetcode.labuladong.popup!", e=>{
    e && alert(".leetcode.labuladong.content-script.leetcode.labuladong.:" + e)
  }
  )
}
),
chrome.runtime.onMessage.addListener(function(e, t, o) {
  console.log(".leetcode.labuladong.content-script.leetcode.labuladong.:"),
  console.log(e, t, o),
  o(".leetcode.labuladong.popup,.leetcode.labuladong.:" + JSON.stringify(e))
}),
$("#connect_to_content_script").click(()=>{
  e(e=>{
    var t = chrome.tabs.connect(e, {
      name: "test-connect"
    });
    t.postMessage({
      question: ".leetcode.labuladong.?"
    }),
    t.onMessage.addListener(function(e) {
      alert(".leetcode.labuladong.:" + e.answer),
      e.answer && e.answer.startsWith(".leetcode.labuladong.") && t.postMessage({
        question: ".leetcode.labuladong.,.leetcode.labuladong.!"
      })
    })
  }
  )
}
),
$("#update_bg_color").click(()=>{
  var t;
  t = 'document.body.style.backgroundColor="red";',
  e(e=>{
    chrome.tabs.executeScript(e, {
      code: t
    })
  }
  )
}
),
$("#update_font_size").click(()=>{
  t({
    cmd: "update_font_size",
    size: 42
  }, function(e) {})
}
),
$("#show_badge").click(()=>{
  chrome.action.setBadgeText({
    text: "New"
  }),
  chrome.action.setBadgeBackgroundColor({
    color: [255, 0, 0, 255]
  })
}
),
$("#hide_badge").click(()=>{
  chrome.action.setBadgeText({
    text: ""
  }),
  chrome.action.setBadgeBackgroundColor({
    color: [0, 0, 0, 0]
  })
}
);

<!DOCTYPE html>
<html>
<head>
    <title>labuladong 的刷题插件</title>
    <meta charset="utf-8"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <style>
        body {
            font-family: 'Microsoft Yahei';
            min-width: 400px;
            min-height: 100px;
        }

        a {
            margin-right: 10px;
        }
    </style>
</head>
<body>
<h1 id="title"> labuladong 的刷题插件 </h1>
<p>当前插件版本:<strong id="cur_version"></strong></p>
<p>最新插件版本:<strong id="latest_version"></strong></p>
<p>bug 反馈:<a href="https://github.com/labuladong/fucking-algorithm/discussions/704" target="_blank">GitHub
    Discussion</a></p>
<p>插件使用指南:<a id="guide" target="_blank">点这里</a></p>
<p id="notify_line"></p>
<button id="refresh_btn">手动刷新数据</button>
<p>👆仅在插件有异常时尝试刷新,❌ 表示未购买或未登录课程</p>
<p id="refresh_status"></p>

<h2>配套学习工具</h2>
<p><a target="_blank" href="https://mp.weixin.qq.com/s/X-fE9sR4BLi6T9pn7xP4pg">配套 PDF 教材最新版本:<strong id="pdf_latest_version"></strong></a></p>
<p><a target="_blank" href="https://mp.weixin.qq.com/s/z4mqiiJV9pZ3t6SIPa2kTA">配套 vscode 插件最新版本:<strong id="vscode_latest_version"></strong></a></p>
<p><a target="_blank" href="https://mp.weixin.qq.com/s/NF8mmVyXVfC1ehdMOsO7Cw">配套 jetbrains 插件最新版本:<strong id="jb_latest_version"></strong></a></p>
<p><a target="_blank" href="https://aep.h5.xeknow.com/s/1XJHEO">数据结构精品课最新版本:<strong id="ds_latest_version"></strong></a></p>
<p><a target="_blank" href="https://mp.weixin.qq.com/s/eUG2OOzY3k_ZTz-CFvtv5Q">刷题打卡挑战:<strong id="challenge_latest_version"></strong></a></p>

<script type="text/javascript" src="js/jq.js"></script>
<script type="text/javascript" src="js/popup.js"></script>
</body>
</html>

作者:xgqfrms 链接:https://www.cnblogs.com/xgqfrms/p/17124922.html 来源:https://www.cnblogs.com 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 ©xgqfrms 2012-2023 www.cnblogs.com 发布文章使用:只允许注册用户才可以访问! 原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!

xgqfrms commented 1 year ago

https://github.com/labuladong/fucking-algorithm

xgqfrms commented 1 year ago

https://www.cnblogs.com/xgqfrms/p/17124922.html#5149650

xgqfrms commented 1 year ago
chrome.runtime.onMessage.addListener(function(n, e, t) {
  if ("brief" === n.statusType) {
    console.log(n);
    var c = n.file.split(".")[0].split("_")[0];
    if (!u.includes(c)) {
      u.push(c);
      let o = c + n.status + "; ";
      if (n.hasOwnProperty("xe_id")) {
        let e = n.xe_id
          , t = `https://appktavsiei5995.pc.xiaoe-tech.com/detail/${e}/1`;
        e.startsWith("p_") && (t = `https://appktavsiei5995.pc.xiaoe-tech.com/detail/${e}/8`),
        o = `<a href='${t}' target="_blank">${o}</a>`
      }
      $("#refresh_status").append(`<span>${o}</span>`)
    }
  }
}),

https://appktavsiei5995.pc.xiaoe-tech.com

=>

https://www.xiaoe-tech.com/

image

小鹅通提供技术支持

https://www.xiaoe-tech.com/

小鹅通_知识产品与用户服务的私域运营工具