Skip to content

Instantly share code, notes, and snippets.

@i-sync
Created April 30, 2024 13:57
Show Gist options
  • Save i-sync/84d4f2847e17ba9e899ff79b1814063a to your computer and use it in GitHub Desktop.
Save i-sync/84d4f2847e17ba9e899ff79b1814063a to your computer and use it in GitHub Desktop.
Hook Sitecore API, Update NameValue key field set field width to 500px

Hook Sitecore API, Update NameValue key field set field width to 500px

Before Update

After Update

// ==UserScript==
// @name Modify Element Width
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Modify the width of a specific element on a webpage
// @author Michael
// @match https://sc.dev.local/*
// @require https://unpkg.com/ajax-hook@2.0.3/dist/ajaxhook.min.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
ah.proxy({
//请求发起前进入
onRequest: (config, handler) => {
handler.next(config);
},
//请求发生错误时进入,比如超时;注意,不包括http状态码错误,如404仍然会认为请求成功
onError: (err, handler) => {
//console.log(err.type);
handler.next(err);
},
//请求成功后进入
onResponse: (response, handler) => {
if(response.config.url.indexOf('/sitecore/shell/applications/content-editor') > -1) {
// console.log("url:", response.config.url);
// rewrite response
// console.log(response.response);
var res = response.response.replace(/style=\\"width:150px\\"/g, 'style=\\\"width:500px\\\"');
// console.log(res);
response.response = res;
}
handler.next(response);
}
})
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment