-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
82 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module "routes"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,51 @@ | ||
import { UnauthorizedError } from "./api"; | ||
import diffSelect from "./features/diff-select"; | ||
import fadeOutUnrelatedCommits from "./features/fade-out-unrelated-commits"; | ||
import mergeWarning from "./features/merge-warning"; | ||
import parentPRSelect from "./features/parent-pr-select"; | ||
import showStackingInList from "./features/show-stacking-in-list"; | ||
import { setConfig } from "./lib/config"; | ||
import { createContext } from "./lib/context"; | ||
import { isPRView } from "./lib/location"; | ||
// import { UnauthorizedError } from "./api"; | ||
// import diffSelect from "./features/diff-select"; | ||
// import fadeOutUnrelatedCommits from "./features/fade-out-unrelated-commits"; | ||
// import mergeWarning from "./features/merge-warning"; | ||
// import parentPRSelect from "./features/parent-pr-select"; | ||
// import showStackingInList from "./features/show-stacking-in-list"; | ||
// import { setConfig } from "./lib/config"; | ||
// import { createContext } from "./lib/context"; | ||
|
||
async function run() { | ||
if (!isPRView(document.location)) { | ||
return; | ||
} | ||
const context = await createContext(document.location); | ||
try { | ||
await diffSelect(context); | ||
await showStackingInList(context); | ||
await parentPRSelect(context); | ||
await fadeOutUnrelatedCommits(context); | ||
await mergeWarning(context); | ||
} catch (err) { | ||
if (err instanceof UnauthorizedError) { | ||
const token = window.prompt("Please enter an access token"); | ||
if (token) { | ||
setConfig({ token }); | ||
window.location.reload(); | ||
} | ||
} | ||
// tslint:disable-next-line no-console | ||
console.log(err); | ||
} | ||
} | ||
// import { isPRView } from "./lib/location"; | ||
import createRouter from "./lib/router"; | ||
|
||
const observer = new MutationObserver(run); | ||
const el = document.querySelector("#js-repo-pjax-container"); | ||
createRouter({ | ||
"/:owner/:repo/pulls": ({ repo, owner }: { repo: string; owner: string }) => | ||
console.log(repo, owner) | ||
}); | ||
|
||
if (el) { | ||
observer.observe(el, { | ||
childList: true | ||
}); | ||
} | ||
// async function run() { | ||
// if (!isPRView(document.location)) { | ||
// return; | ||
// } | ||
// const context = await createContext(document.location); | ||
// try { | ||
// await diffSelect(context); | ||
// await showStackingInList(context); | ||
// await parentPRSelect(context); | ||
// await fadeOutUnrelatedCommits(context); | ||
// await mergeWarning(context); | ||
// } catch (err) { | ||
// if (err instanceof UnauthorizedError) { | ||
// const token = window.prompt("Please enter an access token"); | ||
// if (token) { | ||
// setConfig({ token }); | ||
// window.location.reload(); | ||
// } | ||
// } | ||
// // tslint:disable-next-line no-console | ||
// console.log(err); | ||
// } | ||
// } | ||
|
||
run(); | ||
// const observer = new MutationObserver(run); | ||
// const el = document.querySelector("#js-repo-pjax-container"); | ||
|
||
// if (el) { | ||
// observer.observe(el, { | ||
// childList: true | ||
// }); | ||
// } | ||
|
||
// run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Router from "routes"; | ||
import { parse } from "url"; | ||
|
||
export default function createRouter(routes: { | ||
[path: string]: (...args: any[]) => void; | ||
}) { | ||
const router = Router(); | ||
|
||
Object.keys(routes).forEach(path => { | ||
router.addRoute(path, routes[path]); | ||
}); | ||
|
||
const pushState = window.history.pushState; | ||
|
||
window.history.pushState = (...args: any[]) => { | ||
const [, , url] = args; | ||
console.log(parse(url).pathname); | ||
|
||
console.log(router.match(parse(url).pathname)); | ||
|
||
return pushState.apply(history, args); | ||
}; | ||
console.log(router.match(location.pathname)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,8 @@ | |
"extends": [ | ||
"tslint:latest", | ||
"tslint-config-prettier" | ||
] | ||
], | ||
"rules": { | ||
"no-submodule-imports": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters