Skip to content
This repository has been archived by the owner on Nov 28, 2024. It is now read-only.

Add button to block account with a single click. #13

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ It's a chrome\firefox extension (that also works on android), that lets you filt
- Hide 'Promoted' posts
- ~Hide anonymous 9GAGGER posts~ [9gag removed anons]
- ~Hide posts by tags or words in the title~ [This is now a native option in the settings]
- Add button to block account with a single click.

## How to install
Chrome: [Download on the Chrome webstore](https://chrome.google.com/webstore/detail/9gag-post-filter/ajkipkkhchaaccpbpkclolpebkgbmodl)\
Expand Down
Binary file removed assets/icons/logo.jpg
Binary file not shown.
Binary file added assets/icons/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 30 additions & 3 deletions assets/js/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,34 @@ const clickEvent = new MouseEvent("click", {
"cancelable": false
});
var k = 0; //numerical id for id-less elements, mostly on mobile browser
chrome.storage.local.get( ['show_days',"min_days","anon","verified","promoted","tags","title","spammers","spammers_hours","cheers"], data => {
chrome.storage.local.get( ['show_days',"min_days","anon","verified","promoted","tags","title","spammers","spammers_hours","cheers", "block"], data => {
settings = data;
if(settings.tags !== undefined){
$tags = settings.tags;
$tags = $tags.trim().split(",");
}
} );

let script = document.createElement("script")
const innerHTML = `
const blockAccount = async (accountId, art_id) => {
const body = "accountId=" + accountId + "&_method=post"
const requestInited = {
method: 'POST',
headers: {
"Content-Type" : "application/x-www-form-urlencoded;charset=UTF-8"
},
body
}
await fetch("https://9gag.com/v1/user-block", requestInited)
let el = document.querySelector("#"+art_id)
el.remove()
}
`
script.innerHTML = innerHTML
$("head").append(script)


const getNameFromMenu = async (art_id)=>{
if(document.querySelector("#"+art_id+" .uikit-popup-menu") !== null){ //desktop
let el = document.querySelector("#"+art_id+" .uikit-popup-menu");
Expand Down Expand Up @@ -131,7 +152,7 @@ const myTimeout = setTimeout(function(){
//console.log(json);
let creatorCreation = json.data.profile.creationTs;
//console.log(article,'creator ts',creatorCreation);

const accountId = json.data.profile.accountId

let now = Date.now()/1000;
let diff = now-creatorCreation;
Expand Down Expand Up @@ -205,9 +226,15 @@ const myTimeout = setTimeout(function(){
$("#"+art_id+" .post-vote").append(`<span class="post-vote__text downvote">${downvotes}</span>`);
$("#"+art_id+" .downvote.grouped ").after(`<span class="post-vote__text downvote">${downvotes}</span>`);
}

if(settings.block){
const button = `<button style="color:red;" onClick="blockAccount('${accountId}', '${art_id}')">Block</button>`
$("#"+art_id+" .post-header__left").append(button);
$("#"+art_id+" .post-meta.mobile").append(button);
}

}
try{
try{
console.debug("tring to enable controls for "+art_id,$("#"+art_id+""))
$("#"+art_id+" video").prop("controls",true); //enable controls for videos
}catch(e){
Expand Down
10 changes: 9 additions & 1 deletion assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ var $title_checkbox = $("#title_checkbox");
var $spammers_checkbox = $("#spammers_checkbox");
var $spammers_input = $("#spammers_input");
var $cheers_checkbox = $("#cheers_checkbox");
var $block_checkbox = $("#block_checkbox");


// $(document).ready(async function(){

chrome.storage.local.get( ['show_days',"min_days","anon","verified","promoted","tags","title","spammers","spammers_hours","cheers"], data => {
chrome.storage.local.get( ['show_days',"min_days","anon","verified","promoted","tags","title","spammers","spammers_hours","cheers", "block"], data => {
// alert(data.show_days);
$show_days.prop('checked', data.show_days);
$anon_checkbox.prop('checked', data.anon);
Expand All @@ -24,6 +25,7 @@ var $cheers_checkbox = $("#cheers_checkbox");
$spammers_checkbox.prop('checked', data.spammers);
$spammers_input.val(data.spammers_hours);
$cheers_checkbox.prop('checked', data.cheers);
$block_checkbox.prop('checked', data.block);
} );

$show_days.on("change", async function(){
Expand Down Expand Up @@ -88,6 +90,12 @@ var $cheers_checkbox = $("#cheers_checkbox");
// alert("Value is set to " + $show_days.prop("checked"));
});
});

$block_checkbox.on("change", async function(){
chrome.storage.local.set({ "block": $block_checkbox.prop("checked") }).then(() => {
// alert("Value is set to " + $block_checkbox.prop("checked"));
});
});
// })


Expand Down
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ <h1>9GAG Posts Filter</h1>
</br>
<label for="cheers">Hide cheers</label>
<input type="checkbox" name="cheers" id="cheers_checkbox">
</br>
<label for="block">Add Block Button</label>
<input type="checkbox" name="block" id="block_checkbox">
</div>
</br>
<a href="https://github.com/AmitBokoDev/9gag-post-filter" id="sauce">view sauce code</a>
Expand Down
49 changes: 26 additions & 23 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
{
"name": "9gag post filter",
"description": "A post filter for 9GAG.com",
"version": "1.1.6",
"browser_specific_settings": {
"gecko": {
"id": "amitbokodev@gmail.com",
"strict_min_version": "42.0"
}
},
"manifest_version": 3,
"permissions": [
"storage"
],
"action": {
"default_popup": "index.html"
},
"content_scripts": [{
"css": ["assets/css/content.css"],
"js": ["assets/js/jquery_slim_mini.js","assets/js/content.js"],
"matches": ["https://9gag.com/*"],
"content_security_policy": "script-src 'self' 'unsafe-inline'; object-src 'self'"
}]
}
"name": "9gag post filter",
"description": "A post filter for 9GAG.com",
"version": "1.1.6",
"browser_specific_settings": {
"gecko": {
"id": "amitbokodev@gmail.com",
"strict_min_version": "42.0"
}
},
"manifest_version": 3,
"permissions": ["storage"],
"action": {
"default_popup": "index.html"
},
"content_scripts": [
{
"css": ["assets/css/content.css"],
"js": ["assets/js/jquery_slim_mini.js", "assets/js/content.js"],
"matches": ["https://9gag.com/*"],
"content_security_policy": "script-src 'self' 'unsafe-inline'; object-src 'self'"
}
],
"icons": {
"16": "assets/icons/logo.png"
}
}