Skip to content

Commit c3efc40

Browse files
committed
Report version to server
Closes #29
1 parent 87c6ee5 commit c3efc40

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

assets/js/modules/angular/decorateHttpService.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import GM from 'greasemonkey';
2020
import angular from 'angular';
21+
import $ from 'jquery';
2122

2223
// TODO: Since we're not using the original service at all, we might
2324
// as well completely replace it rather than decorate it...
@@ -39,6 +40,11 @@ export default function ($provide: any) {
3940
};
4041
const JSON_PROTECTION_PREFIX = /^\)\]\}',?\n/;
4142

43+
const DEFAULT_HEADERS = {
44+
Accept: APPLICATION_JSON,
45+
'X-QCExt-Version': GM.info.script.version
46+
};
47+
4248
function isJsonLike(str) {
4349
const jsonStart = str.match(JSON_START);
4450

@@ -103,13 +109,17 @@ export default function ($provide: any) {
103109
const $q = injector.get('$q');
104110
const ourHttp = {
105111
get: function (url, config) {
112+
config = config || {};
113+
114+
let headers: any = DEFAULT_HEADERS;
115+
if (config.headers) {
116+
headers = $.extend({}, DEFAULT_HEADERS, config.headers);
117+
}
106118
return $q(function (resolve, reject) {
107119
GM.xmlHttpRequest({
108120
method: 'GET',
109121
url: url,
110-
headers: {
111-
Accept: APPLICATION_JSON
112-
},
122+
headers: headers,
113123
onload: function (gmResponse) {
114124
const headers = getHeaderFunction(
115125
gmResponse.responseHeaders
@@ -153,8 +163,10 @@ export default function ($provide: any) {
153163
const contentType = 'contentType' in config ? config.contentType : APPLICATION_JSON;
154164
const dataTransform = 'dataTransform' in config ? config.dataTransform : (d) => JSON.stringify(d);
155165

156-
const headers = {};
157-
headers.Accept = APPLICATION_JSON;
166+
let headers: any = DEFAULT_HEADERS;
167+
if (config.headers) {
168+
headers = $.extend({}, DEFAULT_HEADERS, config.headers);
169+
}
158170
if (contentType) {
159171
headers['Content-Type'] = contentType;
160172
}

0 commit comments

Comments
 (0)