Compare commits

...

13 Commits

Author SHA1 Message Date
Mitesh Shah ddee07a2d2 feat: add youtube link 2020-09-13 22:32:44 +05:30
nilesh 870c46de65 Bump version to 0.5.0 2020-09-13 20:59:08 +05:30
Mitesh Shah fcc58fb8d1 feat: update demo video 2020-09-13 20:13:59 +05:30
Mitesh Shah 059c8e26c0 feat: added another demo video 2020-09-13 19:57:34 +05:30
Mitesh Shah fc2ee60825 feat: demo video link 2020-09-13 19:55:27 +05:30
Mitesh e9605d2c21
Merge pull request #48 from nileshtrivedi/create-pull-request/patch-ks2vt1i
Changes by create-pull-request action
2020-09-13 19:52:22 +05:30
oxalorg df91f1bfbb [create-pull-request] automated change 2020-09-13 14:22:04 +00:00
Mitesh 8d069202ca
Merge pull request #46 from nileshtrivedi/feature-toobar-popup-suggestion 2020-09-13 19:47:28 +05:30
Mitesh Shah 5900205dee fix: typo 2020-09-13 19:47:09 +05:30
Mitesh Shah 7decb2a39f feat: toolbar popup to suggest new alternatives 2020-09-13 19:43:23 +05:30
Anirudh Varma bde303215c
Fix the action path for good (#42) 2020-09-13 18:50:17 +05:30
Anirudh Varma bcdec9ba2c
Try to fix action path (#40) 2020-09-13 18:35:33 +05:30
Anirudh Varma 593c99c478
Add workflows and actions files (#38) 2020-09-13 18:28:09 +05:30
8 changed files with 729 additions and 553 deletions

5
.github/actions/action.yml vendored Normal file
View File

@ -0,0 +1,5 @@
name: "Better Suggestions"
description: "A GitHub action to allow users to suggest changes alternative."
runs:
using: 'node12'
main: 'index.js'

42
.github/actions/index.js vendored Normal file
View File

@ -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));
});

25
.github/workflows/main.yml vendored Normal file
View File

@ -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"

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -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/*"]
}

48
toolbar/popup.html Normal file
View File

@ -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>

39
toolbar/popup.js Normal file
View File

@ -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();
});