Compare commits
13 Commits
1c4e6ffcfb
...
ddee07a2d2
Author | SHA1 | Date |
---|---|---|
Mitesh Shah | ddee07a2d2 | |
nilesh | 870c46de65 | |
Mitesh Shah | fcc58fb8d1 | |
Mitesh Shah | 059c8e26c0 | |
Mitesh Shah | fc2ee60825 | |
Mitesh | e9605d2c21 | |
oxalorg | df91f1bfbb | |
Mitesh | 8d069202ca | |
Mitesh Shah | 5900205dee | |
Mitesh Shah | 7decb2a39f | |
Anirudh Varma | bde303215c | |
Anirudh Varma | bcdec9ba2c | |
Anirudh Varma | 593c99c478 |
|
@ -0,0 +1,5 @@
|
|||
name: "Better Suggestions"
|
||||
description: "A GitHub action to allow users to suggest changes alternative."
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'index.js'
|
|
@ -0,0 +1,42 @@
|
|||
const fs = require("fs");
|
||||
|
||||
const PREFIX = "Suggestion:";
|
||||
|
||||
function parseURLFromIssueTitle(title) {
|
||||
return title.replace(PREFIX, "").trim();
|
||||
}
|
||||
|
||||
function findExistingMatchForUrl(url, list) {
|
||||
return list.findIndex((listItem) => {
|
||||
const match = url.match(new RegExp(listItem.urlPattern));
|
||||
return match;
|
||||
});
|
||||
}
|
||||
|
||||
fs.readFile(`${process.env.GITHUB_WORKSPACE}/defaultlist.json`, function (err, file) {
|
||||
if (err) {
|
||||
return console.log("Unable to scan directory: " + err);
|
||||
}
|
||||
const database = JSON.parse(file.toString());
|
||||
const gh_context = JSON.parse(process.env.gh_context);
|
||||
const issueTitle = gh_context.event.issue.title;
|
||||
if (!issueTitle.startsWith(PREFIX)) {
|
||||
return;
|
||||
}
|
||||
const [suggestedUrl, name, ...descriptions] = gh_context.event.issue.body.split("\n");
|
||||
const url = parseURLFromIssueTitle(issueTitle);
|
||||
const existingIndex = findExistingMatchForUrl(url, database);
|
||||
console.log("Index for url", url, existingIndex);
|
||||
const newItem = { url: suggestedUrl.trim(), name: name.trim(), desc: descriptions.join() };
|
||||
console.log("New Item", newItem);
|
||||
if (existingIndex === -1) {
|
||||
const item = {
|
||||
urlPattern: url,
|
||||
alternatives: [newItem],
|
||||
};
|
||||
database.push(item);
|
||||
} else {
|
||||
database[existingIndex].alternatives.push(newItem);
|
||||
}
|
||||
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/defaultlist.json`, JSON.stringify(database, null, 4));
|
||||
});
|
|
@ -0,0 +1,25 @@
|
|||
name: Issues Workflow
|
||||
|
||||
# Controls when the action will run.
|
||||
on:
|
||||
issues:
|
||||
types: [opened]
|
||||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
|
||||
jobs:
|
||||
# This workflow contains a single job called "build"
|
||||
build:
|
||||
env:
|
||||
gh_context: ${{ toJson(github) }}
|
||||
# The type of runner that the job will run on
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
# Steps represent a sequence of tasks that will be executed as part of the job
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
|
||||
- uses: ./.github/actions
|
||||
- uses: peter-evans/create-pull-request@v3
|
||||
name: Create Pull Request
|
||||
with:
|
||||
branch-suffix: random
|
||||
labels: "Default List Suggestion"
|
|
@ -27,7 +27,14 @@ The pop-up shows an option to dismiss the suggestion forever for the current URL
|
|||
You can load this extension directly in Chrome or Firefox Developer Edition (after setting `xpinstall.signatures.required` to `false` in `about:config`).
|
||||
|
||||
To submit to the stores, build a zip with: `zip -r -X archive.zip ./*`
|
||||
Before creating the zip, make sure to uncomment the local reference to `listUrl` in `onStartup()` and for Chrome store, remove `browser_specific_settings` from `manifest.json`
|
||||
Before creating the zip for the Chrome store, remove `browser_specific_settings` from `manifest.json`
|
||||
|
||||
# Demo Video
|
||||
|
||||
You can view 2 demo videos here:
|
||||
|
||||
- https://oxal.org/better-demo.mp4 ([YouTube Link](https://youtu.be/PcBA3SnY67s))
|
||||
- https://oxal.org/better-2.mov
|
||||
|
||||
# Contribute
|
||||
|
||||
|
|
1105
defaultlist.json
1105
defaultlist.json
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "Better",
|
||||
"version": "0.1.0",
|
||||
"version": "0.5.0",
|
||||
"icons": {
|
||||
"48": "images/48.png",
|
||||
"128": "images/128.png"
|
||||
|
@ -11,7 +11,7 @@
|
|||
}
|
||||
},
|
||||
"description": "This extension looks at your current URL, and recommends BETTER product/service alternatives via an in-page pop-up.",
|
||||
"permissions": ["storage"],
|
||||
"permissions": ["storage", "tabs"],
|
||||
"background": {
|
||||
"scripts": ["background.js"],
|
||||
"persistent": false
|
||||
|
@ -27,5 +27,10 @@
|
|||
"page": "options.html",
|
||||
"open_in_tab": false
|
||||
},
|
||||
"browser_action": {
|
||||
"default_icon": "images/48.png",
|
||||
"default_title": "Better",
|
||||
"default_popup": "toolbar/popup.html"
|
||||
},
|
||||
"web_accessible_resources": ["defaultlist.json", "lists/*"]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
|
||||
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container" style="max-width: 420px">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h2 class="font-weight-bold">Better</h2>
|
||||
<p class="lead">Suggest an alternative service for this URL</p>
|
||||
<div class="alert alert-info" id="currentURL"></div>
|
||||
<form action="" method="GET" id="betterForm">
|
||||
<div class="form-group">
|
||||
<label for="basic-url">Better Name</label>
|
||||
<div class="input-group mb-3">
|
||||
<input type="text" id="betterName" name="betterName" class="form-control" id="basic-url">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="basic-url">Better URL</label>
|
||||
<div class="input-group mb-3">
|
||||
<input type="url" id="betterURL" name="betterURL" class="form-control" id="basic-url">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="basic-url">Better description</label>
|
||||
<div class="input-group mb-3">
|
||||
<input type="text" id="betterDescription" name="betterDescription" class="form-control" id="basic-url">
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn btn-warning font-weight-bold" id="suggestionSubmit">Submit suggestion</button>
|
||||
</form>
|
||||
<p class="text-muted">This will take you to a GitHub issue page</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="error-content" class="hidden">
|
||||
</div>
|
||||
<script src="popup.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,39 @@
|
|||
let currentURL = document.getElementById("currentURL");
|
||||
|
||||
chrome.tabs.query(
|
||||
{
|
||||
active: true,
|
||||
currentWindow: true,
|
||||
},
|
||||
function (tabs) {
|
||||
var tabURL = tabs[0].url;
|
||||
currentURL.textContent = tabURL;
|
||||
}
|
||||
);
|
||||
|
||||
let betterForm = document.getElementById("betterForm");
|
||||
let betterName = document.getElementById("betterName");
|
||||
let betterURL = document.getElementById("betterURL");
|
||||
let betterDescription = document.getElementById("betterDescription");
|
||||
|
||||
function encodeQueryData(data) {
|
||||
const ret = [];
|
||||
for (let d in data)
|
||||
ret.push(encodeURIComponent(d) + "=" + encodeURIComponent(data[d]));
|
||||
return ret.join("&");
|
||||
}
|
||||
|
||||
var submitSuggestion = function () {
|
||||
const data = {
|
||||
title: `Suggestion: ${currentURL.textContent}`,
|
||||
body: `${betterURL.value}\n${betterName.value}\n${betterDescription.value}`,
|
||||
};
|
||||
const queryString = encodeQueryData(data);
|
||||
let suggestionUrl = `https://github.com/nileshtrivedi/better/issues/new?${queryString}`;
|
||||
chrome.tabs.create({ url: suggestionUrl });
|
||||
};
|
||||
|
||||
betterForm.addEventListener("submit", function (e) {
|
||||
e.preventDefault();
|
||||
submitSuggestion();
|
||||
});
|
Loading…
Reference in New Issue