小编tru*_*ktr的帖子

一个简单的正则表达式搜索和替换在PHP中缩小/压缩javascript?

你可以在php中发布正则表达式搜索和替换来缩小/压缩javascript吗?

例如,这是一个简单的CSS

  header('Content-type: text/css');
  ob_start("compress");
  function compress($buffer) {
    /* remove comments */
    $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
    /* remove tabs, spaces, newlines, etc. */
    $buffer = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), '', $buffer);
    return $buffer;
  }

  /* put CSS here */

  ob_end_flush();
Run Code Online (Sandbox Code Playgroud)

这是html的一个:

<?php
/* Minify All Output - based on the search and replace regexes. */
function sanitize_output($buffer)
{
    $search = array(
        '/\>[^\S ]+/s', //strip whitespaces after tags, except space
        '/[^\S ]+\</s', //strip whitespaces …
Run Code Online (Sandbox Code Playgroud)

javascript php compression minify

7
推荐指数
1
解决办法
5884
查看次数

如何创建一个检测布尔变量是否为真的事件监听器?

例如,我有var menu_ready = false;.我有一个ajax函数,menu_ready当ajax完成时设置为true:

//set up event listener here

$(...).load(..., function() {
    ...
    menu_ready = true;
}
Run Code Online (Sandbox Code Playgroud)

如何设置等待为menu_ready真的事件监听器?

javascript jquery events event-handling

7
推荐指数
3
解决办法
1万
查看次数

如何在地址栏中为Chrome扩展程序添加图标?

我不知道该怎么做,文档似乎没有让这个显而易见.

我尝试制作background_page并放入chrome.pageAction.show(tab.id);其中,但这似乎不起作用.

我不想使用该browser_action图标,因为该图标仅反映了插件的状态,但它不是用于执行任何操作的按钮.

如何在任何页面/标签的地址栏中添加page_action的图标?

编辑:这是我的manifest.json:

{
    "name": "My Very First Extension :D",
    "version": "0.0.1",
    "description": "Awesomeness",
    "background_page": "background.html",

    "page_action": {
        "default_icon": "icon.png"
    },

    "content_scripts": [{
        "matches": ["http://*/*", "https://*/*"],
        "js": ["mmm.js"]
    }]
}
Run Code Online (Sandbox Code Playgroud)

其中icon.png是一个19x19像素的PNG图形.这是background.html源代码,我正在尝试为所有选项卡显示page_action图标:

<!DOCTYPE html>
<html>
    <head>
        <script>
            chrome.pageAction.show(tab.id);
        </script>
    </head>
</html>
Run Code Online (Sandbox Code Playgroud)

google-chrome chromium google-chrome-extension

7
推荐指数
1
解决办法
1万
查看次数

7
推荐指数
2
解决办法
3055
查看次数

无论JComponent是什么焦点,你如何为JFrame进行键绑定?

我们如何为JFrame创建键绑定,而不管帧中的焦点是什么?

我已经看过这个问题了:你如何为java.awt.Frame创建键绑定?

我尝试为JFrame的根窗格设置输入映射,但是当焦点位于JTextArea上时,即使editable为false,它也不起作用.

使密钥绑定在整个JFrame中工作的最简单方法是什么?

java swing keylistener key-bindings jframe

7
推荐指数
3
解决办法
5694
查看次数

致命:参考格式无效:'refs/heads/master~'

当我尝试以下任何命令时:

git branch
git branch -a
git pull
git log --pretty=format:"%C(yellow)%h%Cred%d\\ %Cblue[%cn]\\%Creset %s" --decorate --graph
git log --online --decorate --graph
Run Code Online (Sandbox Code Playgroud)

我收到了错误

fatal: Reference has invalid format: 'refs/heads/master~'
Run Code Online (Sandbox Code Playgroud)

但以下命令有效:

git log --oneline --graph # removed --decorate
git log
Run Code Online (Sandbox Code Playgroud)

运行

find ./ -iname "*conflict*"
Run Code Online (Sandbox Code Playgroud)

不会返回任何结果.

输出find ./ -name "*master*" | grep "\./\.git"

./.git/logs/refs/heads/master
./.git/logs/refs/heads/master~
./.git/logs/refs/remotes/origin/master
./.git/refs/heads/master
./.git/refs/heads/master~
./.git/refs/remotes/origin/master
Run Code Online (Sandbox Code Playgroud)

不知道这是否有帮助,但我master~在那里看到了.

知道什么可能是错的吗?我可以为您提供哪些其他信息?

git

7
推荐指数
1
解决办法
6268
查看次数

是否可以获得"setter"的setter函数的引用?

例如,在此代码中

var o = {
  set a(value) {this.b = value},
  get a() {return this.b}
}
Run Code Online (Sandbox Code Playgroud)

是否有可能获得对该setter函数o.a的引用,以便如果引用被赋值,f那么我可以f.call(other, value)在另一个对象上使用它?

javascript getter-setter

7
推荐指数
1
解决办法
998
查看次数

为什么主线程会阻止CSS转换动画?

我举了一个例子,对CSS转换进行动画处理,然后单击它,动画被1秒长的循环阻塞。怎么来的?我认为动画转换发生在单独的线程上。

这是示例(单击它以阻塞主线程并因此暂停动画):

window.addEventListener('click', kill)

function kill() {
  var start = +new Date;
  while (+new Date - start < 2000){}
}
Run Code Online (Sandbox Code Playgroud)
    html, body, div {
        width: 100%; height: 100%;
        margin: 0; padding: 0;
        /* background: #364659; */
        /* background: #293442; */
        background: #1E2630;
    }

    @keyframes ShimmerEffect {
        0% { transform: translate3d(-15%, -15%, 0) }
        100% { transform: translate3d(-60%, -60%, 0) }
    }
    .shimmerSurface {
/*         overflow: hidden; */
/*         perspective: 100000px */
    }
    .shimmerSurfaceContent {
        transform-style: preserve-3d;
        background: linear-gradient(
            -45deg,
            rgba(0,0,0,0) …
Run Code Online (Sandbox Code Playgroud)

javascript css css-transitions css-transforms css-animations

7
推荐指数
1
解决办法
115
查看次数

告诉 VS Code 始终使用 TypeScript 自动导入的相对路径?

VS Code 会自动导入与baseUrl使用类似 Node 的非相对路径相关的所有内容,这是我不想要的。

我如何告诉 VS Code 使用相对路径导入所有内容(当然 Node 模块除外)?

删除该baseUrl选项不是一个选项,因为我需要它来将fs导入指向fs模块的本地 polyfill 。

我的 tsconfig.json 有这个:

        "baseUrl": "./",
        "paths": {
            "fs/*": [ "./src/util/FileSystem/*" ]
        }
Run Code Online (Sandbox Code Playgroud)

如果除了删除baseUrl选项之外别无他法,那也没有任何好处!

typescript visual-studio-code

7
推荐指数
1
解决办法
2509
查看次数

使用MutationObserver时获取当前MutationRecord的新属性值?

我有一些如下代码,

const observer = new MutationObserver(records => {
    for (const record of records) {
        if (record.type !== 'attributes') continue

        handleAttributeChange(
            record.attributeName!,
            record.oldValue,
            record.target.attributes.getNamedItem(record.attributeName).value,
        )
    }
})
Run Code Online (Sandbox Code Playgroud)

其中handleAttributeChange参数是属性名称、旧值和新值。

但是,正如您所知,第三个参数传递给handleAttributeChange

const observer = new MutationObserver(records => {
    for (const record of records) {
        if (record.type !== 'attributes') continue

        handleAttributeChange(
            record.attributeName!,
            record.oldValue,
            record.target.attributes.getNamedItem(record.attributeName).value,
        )
    }
})
Run Code Online (Sandbox Code Playgroud)

始终是最新的属性值,而不是我们正在迭代的特定突变记录的“新值”(即不是突变发生时观察到的“新值”)。

我们如何获得每个突变发生时观察到的“新值”?

html javascript dom mutation-observers

7
推荐指数
2
解决办法
5420
查看次数