minor code review: use URL() to lookup query parameters

This commit is contained in:
Raymond Hill 2018-09-07 10:43:58 -04:00
parent 8b5a7aa398
commit 8b1c39507e
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 9 additions and 9 deletions

View File

@ -1,7 +1,7 @@
/******************************************************************************* /*******************************************************************************
uBlock Origin - a browser extension to block requests. uBlock Origin - a browser extension to block requests.
Copyright (C) 2014-2018 Raymond Hill Copyright (C) 2014-present Raymond Hill
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -19,7 +19,7 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global CodeMirror */ /* global CodeMirror, uBlockDashboard */
'use strict'; 'use strict';
@ -27,22 +27,22 @@
(function() { (function() {
var q = window.location.search; let params = new URL(document.location).searchParams;
var matches = q.match(/^\?url=([^&]+)/); let assetKey = params.get('url');
if ( !matches || matches.length !== 2 ) { return; } if ( assetKey === null ) { return; }
vAPI.messaging.send( vAPI.messaging.send(
'default', 'default',
{ {
what : 'getAssetContent', what : 'getAssetContent',
url: decodeURIComponent(matches[1]) url: assetKey
}, },
function(details) { details => {
cmEditor.setValue(details && details.content || ''); cmEditor.setValue(details && details.content || '');
} }
); );
var cmEditor = new CodeMirror( let cmEditor = new CodeMirror(
document.getElementById('content'), document.getElementById('content'),
{ {
autofocus: true, autofocus: true,