Skip to content

Commit

Permalink
Report anonymously feature (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
OhMyGuus authored Oct 20, 2022
1 parent e3eed9e commit ab73dbd
Show file tree
Hide file tree
Showing 7 changed files with 314 additions and 60 deletions.
47 changes: 47 additions & 0 deletions .github/ISSUE_TEMPLATE/website_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Website request
description: Report a cookie warning on a website
title: "[REQ]: example.com"
labels: ["Website request"]
assignees:
- OhMyGuus
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to report a cookie warning!
- type: input
id: url
attributes:
label: Website URL
description: The website u want to report
placeholder: ex. google.com
validations:
required: true

- type: input
id: browser
attributes:
label: What browser are u using?
value: Firefox
placeholder: Firefox
validations:
required: true

- type: input
id: version
attributes:
label: Version
description: What version of our software are you running?
value: 1.0.5
placeholder: 1.0.5
validations:
required: true

- type: textarea
id: notes
attributes:
label: Notes
description: Things like videoplayback not working or no scrollbar etc.
placeholder:
validations:
required: false
46 changes: 43 additions & 3 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,48 @@
"description": "Options text for SAVE button."
},

"optionsSaved": {
"message": "Options successfully saved.",
"description": "Message after saving options."
"reportGithub": {
"message": "Report using Github",
"description": "Menu item to report using Github"
},
"reportAnon": {
"message": "Report anonymously",
"description": "Menu item to report anonymously"
},
"reportAnonTitle": {
"message": "Report",
"description": "Translation of 'report' it will be shown like 'Report example.com'"
},
"reportAnonNotes": {
"message": "Notes: ",
"description": "Notes for the report"
},
"reportNotesPlaceholder": {
"message": "Things like:\nVideoplayback not working\nBroken scrollbar\ngray overlay",
"description": "Placeholder for the notes (\n) is a new line & keep it 4 lines"
},
"reportAnonSend": {
"message": "Send report",
"description": "Button to send the report"
},
"reportAnonCancel": {
"message": "Cancel",
"description": "Button to cCancel the report"
},
"genericErrorTitle": {
"message": "Something went wrong",
"description": "Genereric error title"
},
"genericErrorTryAgain": {
"message": "Try again later..",
"description": "Try again later message"
},
"genericErrorBack": {
"message": "Back",
"description": "Back button after error"
},
"menuLoadingText": {
"message": "Loading...",
"description": "Loading messsage"
}
}
71 changes: 62 additions & 9 deletions src/data/context-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ if (!isManifestV3) {
}
// Reporting

function reportWebsite(info, tab) {
function reportWebsite(info, tab, anon, notes, callback) {
if (tab.url.indexOf("http") != 0 || !tabList[tab.id]) {
return;
}
Expand All @@ -389,10 +389,60 @@ function reportWebsite(info, tab) {
iconUrl: "icons/48.png",
});
}
if (!anon) {
chrome.tabs.create({
url: `https://github.com/OhMyGuus/I-Dont-Care-About-Cookies/issues/new?assignees=OhMyGuus&labels=Website+request&template=website_request.yml&title=%5BREQ%5D%3A+${encodeURIComponent(
hostname
)}&url=${encodeURIComponent(hostname)}&version=${encodeURIComponent(
chrome.runtime.getManifest().version
)}&browser=${encodeURIComponent(getBrowserAndVersion())}`,
});
} else {
fetch("https://api.istilldontcareaboutcookies.com/api/report", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
notes,
url: tab.url,
browser: getBrowserAndVersion(),
extensionVersion: chrome.runtime.getManifest().version,
}),
})
.then((response) => response.json())
.then((response) => {
if (
response &&
!response.error &&
!response.errors &&
response.responseURL
) {
chrome.tabs.create({
url: response.responseURL,
});
callback({ error: false });
} else {
callback({ error: true });
}
})
.catch(() => {
callback({ error: true });
});
}
}

chrome.tabs.create({
url: "https://github.com/OhMyGuus/I-Dont-Care-About-Cookies/issues/new",
});
function getBrowserAndVersion() {
const useragent = navigator.userAgent;
if (useragent.includes("Firefox")) {
return useragent.match(/Firefox\/([0-9]+[\S]+)/)[0].replace("/", " ");
} else if (useragent.includes("Chrome")) {
if (navigator.userAgentData.brands.length > 2) {
const { brand, version } = navigator.userAgentData.brands[1];
return brand + " " + version;
}
}
return "Other";
}

// Adding custom CSS/JS
Expand Down Expand Up @@ -525,11 +575,14 @@ chrome.runtime.onMessage.addListener(function (request, info, sendResponse) {
} else if (request.command == "toggle_extension") {
toggleWhitelist(tabList[request.tabId]);
} else if (request.command == "report_website") {
chrome.tabs.create({
url:
"https://github.com/OhMyGuus/I-Dont-Care-About-Cookies/issues/new?assignees=OhMyGuus&labels=Website+request&template=site-request.md&title=%5BREQ%5D+Website+request%3A+" +
encodeURIComponent(tabList[request.tabId].url),
});
reportWebsite(
info,
tabList[request.tabId],
request.anon,
request.notes,
sendResponse
);
return true; // keeps callback open
} else if (request.command == "refresh_page") {
executeScript({
tabId: request.tabId,
Expand Down
44 changes: 41 additions & 3 deletions src/data/menu/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,49 @@
<div style="width: 220px; padding: 10px 10px 0; text-align: center">
<img src="../../icons/32.png" />

<div style="text-align: left; padding: 10px 0; word-wrap: break-word">
<div id="menu_main" class="menu">
<a id="toggle"></a>
<a id="refresh">&#x21bb;</a>
<a id="report"></a>
<a id="options"></a>
<a id="report" data-translate="menuReport"></a>
<a id="options" data-translate="optionsTitle"></a>
</div>

<div id="menu_report" class="menu menu-hidden">
<a id="report_github" data-translate="reportGithub"></a>
<a id="report_anon" data-translate="reportAnon"></a>
</div>

<div id="menu_report_anon" class="menu menu-hidden">
<h3>
<span data-translate="reportAnonTitle"></span>
<span id="hostname">example.com</span>
</h3>
<label data-translate="reportAnonNotes"></label>
<textarea id="report-notes"></textarea>
<button id="report_anon_send" data-translate="reportAnonSend"></button>
<button
id="report_anon_cancel"
data-translate="reportAnonCancel"
></button>
</div>
</div>

<div id="menu_error" class="menu menu-hidden">
<div style="text-align: center">
<h2 data-translate="genericErrorTitle"></h2>
<p data-translate="genericErrorTryAgain"></p>
<a
id="error_back_button"
data-translate="genericErrorBack"
class="menu-item"
></a>
</div>
</div>

<div id="menu_loading" class="menu menu-hidden">
<div style="text-align: center">
<img src="spinner.svg" width="60" fill="#fff" alt="" />
<p data-translate="menuLoadingText"></p>
</div>
</div>

Expand Down
Loading

0 comments on commit ab73dbd

Please sign in to comment.