1
0
mirror of synced 2025-12-27 03:27:58 +08:00

Dev: Add timestamp to url when refresh #3

This commit is contained in:
surunzi
2016-05-18 17:16:52 +08:00
parent fd8d13c0f4
commit 4635a781c0
2 changed files with 16 additions and 4 deletions

View File

@@ -17,7 +17,7 @@ Browse it on your phone: [http://liriliri.github.io/eruda/](http://liriliri.gith
In order to try it for different sites, execute the script below on browser address bar.
```javascript
javascript:(function () { var script = document.createElement('script'); script.src="//liriliri.github.io/eruda/eruda.min.js"; document.body.appendChild(script); script.onload=function () { eruda.init() } })();
javascript:(function () { var script = document.createElement('script'); script.src="//liriliri.github.io/eruda/eruda.min.js"; document.body.appendChild(script); script.onload = function () { eruda.init() } })();
```
## Features

View File

@@ -24,8 +24,20 @@ export default [
name: 'Refresh Page',
fn: function ()
{
window.location.reload();
var url = window.location.href;
window.location.replace(query(url, 'timestamp', util.now()));
},
desc: 'Refresh current page'
desc: 'Add timestamp to url and refresh'
}
];
function query(uri, key, val)
{
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i"),
separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) return uri.replace(re, '$1' + key + "=" + val + '$2');
return uri + separator + key + "=" + val;
}