Skip to content

Commit

Permalink
增加框架中与getcookies扩展的通信数据标记 (#572)
Browse files Browse the repository at this point in the history
* 修改getcookies扩展的通信方法

修改与扩展插件的通信方法,防止因其他扩展滥用postMessage造成的插件失效
#571

* fix format

* fixFormat

* Change(editor): 📝优化cookie处理逻辑,修复代码格式问题
  • Loading branch information
ckx000 authored Jan 28, 2025
1 parent fdcc02d commit 079fe81
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
19 changes: 13 additions & 6 deletions web/static/coffee/har/editor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,19 @@ define (require, exports, module) ->
window.addEventListener("message", (ev) ->
if event.origin != window.location.origin
return

cookie = ev.data
cookie_str = ""
for key, value of cookie
cookie_str += key + '=' + value + '; '
if cookie_str == ''
console.log('没有获得cookie, 您是否已经登录?')
# 排除未带特定key的postMessage
if !cookie.info
return
if cookie.info == 'cookieRaw'
for key, value of cookie.data
cookie_str += key + '=' + value + '; '
if cookie_str == ''
console.log('没有获得cookie, 您是否已经登录?')
return
else if cookie.info == 'get-cookieModReady'
cookie_str = "get-cookie扩展已就绪"
cookie_input?.val(cookie_str)
cookie_input?.scope().$parent.var.value = cookie_str
)
Expand All @@ -74,4 +79,6 @@ define (require, exports, module) ->
'entry_editor'
])

init: -> angular.bootstrap(document.body, ['HAREditor'])
{ init: ->
angular.bootstrap(document.body, ['HAREditor'])
}
22 changes: 15 additions & 7 deletions web/static/har/editor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 20 additions & 9 deletions web/tpl/utils.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,30 @@ <h2 class="text-center">{{ title }}<sup id="qd_header_sup">{% if sup %}{{ versio
}
});
window.addEventListener("message", function(event) {
var cookie, cookie_str, key, ref, value;
if (event.origin != window.location.origin) {
return ;
}

var cookie = event.data;
var cookie_str = "";
for (key in cookie) {
cookie_str += key+'='+cookie[key]+'; '
}
if (cookie_str == '') {
// alert('没有获得cookie,您是否已经登录?');
cookie = event.data;
cookie_str = "";
//排除未带特定key的postMessage
if (!cookie.info) {
return;
}
//if (!cookie.info){cookie_str=="你可能在使用旧版get-cookies插件,请获取更新"};
if (cookie.info === 'cookieRaw') {
ref = cookie.data;
for (key in ref) {
value = ref[key];
cookie_str += key + '=' + value + '; ';
}
if (cookie_str === '') {
console.warn('没有获得cookie, 您是否已经登录?');
return;
}
} else if (cookie.info === 'get-cookieModReady') {
cookie_str = "get-cookie扩展已就绪";
}
$('#input-cookie').val(cookie_str);
}, false);
})
Expand All @@ -203,4 +214,4 @@ <h2 class="text-center">{{ title }}<sup id="qd_header_sup">{% if sup %}{{ versio
$(_id).select2({width: _width });
});
</script>
{% endmacro %}
{% endmacro %}

0 comments on commit 079fe81

Please sign in to comment.