Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
gongzili456 committed Dec 6, 2019
0 parents commit 8f85912
Show file tree
Hide file tree
Showing 10 changed files with 323 additions and 0 deletions.
104 changes: 104 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
27 changes: 27 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict";

chrome.runtime.onInstalled.addListener(function() {
chrome.storage.sync.set({ opening: true });
});

function cleanCookies(url) {
chrome.cookies.getAll({ url }, function(cookies) {
cookies.reduce(function(p, c) {
return p.then(function() {
chrome.cookies.remove({ url, name: c.name }, function(details) {});
});
}, Promise.resolve());
});
}

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
chrome.storage.sync.get("opening", function(data) {
if (data.opening) {
cleanCookies(request.url);

chrome.tabs.sendMessage(sender.tab.id, { action: "refresh" });
}
});

return true; // This is required by a Chrome Extension
});
36 changes: 36 additions & 0 deletions content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"use strict";

// 监听事件,与 background js 通信
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.action === "refresh") {
window.location.reload();
}
});

var callback = function() {
const paywall = document.querySelector("div[id*='paywall']");

const regwall = document.querySelector("div[id*='regwall']");

if (paywall || regwall) {
chrome.runtime.sendMessage({ url: window.location.origin });
}
};

callback();

// 关闭底部登录浮窗
setTimeout(() => {
document
.querySelector("div[id*='lo-meter']")
.querySelector("button")
.click();
}, 3000);

// 关闭中部登录浮窗
setTimeout(() => {
document
.querySelector("div[id*='susi-entry']")
.querySelector("button")
.click();
}, 2000);
Binary file added images/icon128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "Medium Quiet!",
"version": "1.0",
"description": "medium Quiet!",
"permissions": [
"tabs",
"activeTab",
"declarativeContent",
"storage",
"<all_urls>",
"cookies"
],

"options_page": "options.html",

"background": {
"scripts": ["background.js"],
"persistent": false
},

"content_scripts": [
{
"matches": ["https://*.medium.com/*"],
"js": ["content.js"],
"all_frames": true,
"run_at": "document_end"
}
],

"icons": {
"16": "images/icon16.png",
"32": "images/icon32.png",
"48": "images/icon48.png",
"128": "images/icon128.png"
},
"manifest_version": 2
}
83 changes: 83 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<style>
/* The switch - the box around the slider */
.switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}

/* Hide default HTML checkbox */
.switch input {
opacity: 0;
width: 0;
height: 0;
}

/* The slider */
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: 0.4s;
transition: 0.4s;
}

.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: 0.4s;
transition: 0.4s;
}

input:checked + .slider {
background-color: #2196f3;
}

input:focus + .slider {
box-shadow: 0 0 1px #2196f3;
}

input:checked + .slider:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}

/* Rounded sliders */
.slider.round {
border-radius: 34px;
}

.slider.round:before {
border-radius: 50%;
}
</style>
</head>

<body>
<div>
<label class="switch">
<input type="checkbox" id="mm_checkbox" />
<span class="slider round" id="open_switch"></span>
</label>
</div>
<div>
<p id="mm_msg"></p>
</div>
</body>
<script src="options.js"></script>
</html>
36 changes: 36 additions & 0 deletions options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"use strict";

chrome.storage.sync.get("opening", function(data) {
let now = data.opening;
console.log("state: ", now);

toggle(now);
});

function toggle(opening) {
console.log("toggle: ", opening);

chrome.storage.sync.set({ opening }, function() {
let mm_checkbox = document.getElementById("mm_checkbox");

if (opening) {
mm_checkbox.setAttribute("checked", "checked");
} else {
mm_checkbox.removeAttribute("checked");
}

let mm_msg = document.getElementById("mm_msg");
mm_msg.innerText = opening
? "正在使『Medium』保持安静"
: "正在使『自己』 保持安静";
});
}

let switchBtn = document.getElementById("open_switch");

switchBtn.addEventListener("click", function() {
chrome.storage.sync.get("opening", function(data) {
let now = data.opening;
toggle(!now);
});
});

0 comments on commit 8f85912

Please sign in to comment.