Skip to content

Commit d136fab

Browse files
committed
Updating local code snippets from latest github repo, fixes bahmutov#6
1 parent 82e458c commit d136fab

File tree

5 files changed

+35
-7
lines changed

5 files changed

+35
-7
lines changed

README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,33 @@ digest duration for several selectors and print sorted table starting with the s
6969

7070
All snippets, including mine are distributed under MIT license.
7171

72-
## Remote download
72+
## Updating local code snippets
7373

74-
You can download and run a snippet by using the following boilerplate
75-
(scripts are via downloaded via [RawGit](https://rawgit.com/))
74+
You can update local code snippets by downloading new versions from this github repository.
75+
Create a code snippets and copy source from [update-code-snippets.js](update-code-snippets.js).
76+
77+
You will run this code snippet in an unusual way. First, open any web page, even an empty tab.
78+
Open the DevTools in **undocked** mode (Command+Option+I on Mac). Then open the DevTools **again**,
79+
*while focused* on the first DevTools. This will open the second DevTools instance with the source for the
80+
first DevTools panels. If you inspect the `localStorage` variable in the second DevTools window, you will
81+
find lots of interesting stuff, including all the code snippets in the `localStorage.scriptSnippets` property.
82+
83+
Whenever you want to update the your local code snippets in the Chrome DevTools, execute the `update-code-snippets.js`
84+
snippet in the second DevTools instance. The update script looks at the your current code snippets and
85+
tries to download a file with same name from the code snippets github repository (via [RawGit][RawGit]).
86+
If the remote file has been downloaded successfully, it will replace the snippet.
87+
After all snippets are checked, reopen the DevTools to load the updated source code.
88+
89+
![update code snippets](images/update-code-snippets.png)
90+
91+
Note, that only the latest source is downloaded, not any particular release.
92+
Also, only code snippets with names matching existing files in this repo are replaced. If you do not
93+
want to override a code snippet - just rename it, for example, remove the `.js` extension.
94+
95+
## Remote download a single script
96+
97+
You can download and run a single snippet by using the following boilerplate
98+
(scripts are via downloaded via [RawGit][RawGit])
7699

77100
```js
78101
(function firstPaintRemote() {
@@ -109,3 +132,4 @@ Support: if you find any problems with this module, email / tweet /
109132
[2]: http://bahmutov.calepin.co/performance-profiling-using-devtools-code-snippets.html
110133
[3]: http://bahmutov.calepin.co/improving-angular-web-app-performance-example.html
111134
[measure]: http://bahmutov.calepin.co/measure-space-allocation.html
135+
[RawGit]: (https://rawgit.com/)

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "code-snippets",
33
"main": "first-paint.js",
4-
"version": "0.1.4",
4+
"version": "0.2.0",
55
"homepage": "https://github.com/bahmutov/code-snippets",
66
"license": "MIT",
77
"ignore": [

images/update-code-snippets.png

1.26 MB
Loading

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "code-snippets",
33
"description": "Chrome DevTools code snippets ",
4-
"version": "0.1.4",
4+
"version": "0.2.0",
55
"author": "Gleb Bahmutov <gleb.bahmutov@gmail.com>",
66
"bugs": {
77
"url": "https://github.com/bahmutov/code-snippets/issues"

update-code-snippets.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// updates code snippets from remote repo
2+
// See README.md
23
var snippets = JSON.parse(localStorage.scriptSnippets);
34
console.log('I have', snippets.length, 'code snippets');
45
console.table(snippets);
56

6-
// read code snippets from this repo
7+
// read code snippets from this repo via RawGit.com
78
var repo = 'https://rawgit.com/bahmutov/code-snippets/master/';
89

910
function fetch(url) {
@@ -62,6 +63,9 @@ allChecked.then(function () {
6263
});
6364
if (updated.length) {
6465
localStorage.scriptSnippets = JSON.stringify(snippets);
66+
console.table(updated);
67+
console.log('please reopen DevTools to load updated code snippets');
68+
} else {
69+
console.log('nothing to update.');
6570
}
66-
console.table(updated);
6771
});

0 commit comments

Comments
 (0)